src/kernel.c
L_KERNEL *
kernelNormalize(L_KERNEL  *kels,
                l_float32  normsum)
{
l_int32    i, j, sx, sy, cx, cy;
l_float32  sum, factor;
L_KERNEL  *keld;

    PROCNAME("kernelNormalize");

    if (!kels)
        return (L_KERNEL *)ERROR_PTR("kels not defined", procName, NULL);

    kernelGetSum(kels, &sum);
    if (L_ABS(sum) < 0.01) {
        L_ERROR("null sum; not normalizing; returning a copy", procName);
        return kernelCopy(kels);
    }

    kernelGetParameters(kels, &sy, &sx, &cy, &cx);
    if ((keld = kernelCreate(sy, sx)) == NULL)
        return (L_KERNEL *)ERROR_PTR("keld not made", procName, NULL);
    keld->cy = cy;
    keld->cx = cx;

    factor = normsum / sum;
    for (i = 0; i < sy; i++)
        for (j = 0; j < sx; j++)
            keld->data[i][j] = factor * kels->data[i][j];

    return keld;
}
/*!
 *  kernelNormalize()
 *
 *      Input:  kels (source kel, to be normalized)
 *              normsum (desired sum of elements in keld)
 *      Return: keld (normalized version of kels), or null on error
 *                   or if sum of elements is very close to 0)
 *
 *  Notes:
 *      (1) If the sum of kernel elements is close to 0, do not
 *          try to calculate the normalized kernel.  Instead,
 *          return a copy of the input kernel, with an error message.
 */
kernelNormalize()
Input:  kels (source kel, to be normalized)
normsum (desired sum of elements in keld)
Return: keld (normalized version of kels), or null on error
or if sum of elements is very close to 0)

(1) If the sum of kernel elements is close to 0, do not
try to calculate the normalized kernel.  Instead,
return a copy of the input kernel, with an error message.
kernelNormalize () Input : kels ( source kel to be normalized ) normsum ( desired sum of elements in keld ) Return : keld ( normalized version of kels ) or null on error or if sum of elements is very close to 0 ) ( 1 ) If the sum of kernel elements is close to 0 do not try to calculate the normalized kernel . Instead return a copy of the input kernel with an error message .
L_KERNEL *
kernelNormalize(L_KERNEL  *kels,
                l_float32  normsum)
{
l_int32    i, j, sx, sy, cx, cy;
l_float32  sum, factor;
L_KERNEL  *keld;
    PROCNAME("kernelNormalize");
    if (!kels)
        return (L_KERNEL *)ERROR_PTR("kels not defined", procName, NULL);
    kernelGetSum(kels, &sum);
    if (L_ABS(sum) < 0.01) {
        L_ERROR("null sum; not normalizing; returning a copy", procName);
        return kernelCopy(kels);
    }
    kernelGetParameters(kels, &sy, &sx, &cy, &cx);
    if ((keld = kernelCreate(sy, sx)) == NULL)
        return (L_KERNEL *)ERROR_PTR("keld not made", procName, NULL);
    keld->cy = cy;
    keld->cx = cx;
    factor = normsum / sum;
    for (i = 0; i < sy; i++)
        for (j = 0; j < sx; j++)
            keld->data[i][j] = factor * kels->data[i][j];
    return keld;
}
L_KERNEL * kernelNormalize ( L_KERNEL * kels , l_float32 normsum ) { l_int32 i , j , sx , sy , cx , cy ; l_float32 sum , factor ; L_KERNEL * keld ; PROCNAME ( " " ) ; if ( ! kels ) return ( L_KERNEL * ) ERROR_PTR ( " " , procName , NULL ) ; kernelGetSum ( kels , & sum ) ; if ( L_ABS ( sum ) < 0.01 ) { L_ERROR ( " " , procName ) ; return kernelCopy ( kels ) ; } kernelGetParameters ( kels , & sy , & sx , & cy , & cx ) ; if ( ( keld = kernelCreate ( sy , sx ) ) == NULL ) return ( L_KERNEL * ) ERROR_PTR ( " " , procName , NULL ) ; keld -> cy = cy ; keld -> cx = cx ; factor = normsum / sum ; for ( i = 0 ; i < sy ; i ++ ) for ( j = 0 ; j < sx ; j ++ ) keld -> data [ i ] [ j ] = factor * kels -> data [ i ] [ j ] ; return keld ; }
kernelNormalize()
      Input:  kels (source kel, to be normalized)
              normsum (desired sum of elements in keld)
      Return: keld (normalized version of kels), or null on error
                   or if sum of elements is very close to 0)
kernelNormalize () Input : kels ( source kel to be normalized ) normsum ( desired sum of elements in keld ) Return : keld ( normalized version of kels ) or null on error or if sum of elements is very close to 0 )