Leptonica 1.68
C Image Processing Library
|
Optimized low-level implementation of grayscale convolution and binary rank filter. More...
Go to the source code of this file.
Functions | |
void | blockconvLow (l_uint32 *data, l_int32 w, l_int32 h, l_int32 wpl, l_uint32 *dataa, l_int32 wpla, l_int32 wc, l_int32 hc) |
void | blockconvAccumLow (l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 d, l_int32 wpls) |
void | blocksumLow (l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpl, l_uint32 *dataa, l_int32 wpla, l_int32 wc, l_int32 hc) |
Optimized low-level implementation of grayscale convolution and binary rank filter.
Grayscale block convolution void blockconvLow() void blockconvAccumLow() Binary block sum and rank filter void blocksumLow()
Definition in file convolvelow.c.
void blockconvLow | ( | l_uint32 * | data, |
l_int32 | w, | ||
l_int32 | h, | ||
l_int32 | wpl, | ||
l_uint32 * | dataa, | ||
l_int32 | wpla, | ||
l_int32 | wc, | ||
l_int32 | hc | ||
) |
Input: data (data of input image, to be convolved) w, h, wpl dataa (data of 32 bpp accumulator) wpla (accumulator) wc (convolution "half-width") hc (convolution "half-height") Return: void
Notes: (1) The full width and height of the convolution kernel are (2 * wc + 1) and (2 * hc + 1). (2) The lack of symmetry between the handling of the first (hc + 1) lines and the last (hc) lines, and similarly with the columns, is due to fact that for the pixel at (x,y), the accumulator values are taken at (x + wc, y + hc), (x - wc - 1, y + hc), (x + wc, y - hc - 1) and (x - wc - 1, y - hc - 1). (3) We compute sums, normalized as if there were no reduced area at the boundary. This under-estimates the value of the boundary pixels, so we multiply them by another normalization factor that is greater than 1. (4) This second normalization is done first for the first hc + 1 lines; then for the last hc lines; and finally for the first wc + 1 and last wc columns in the intermediate lines. (5) The caller should verify that wc < w and hc < h. Under those conditions, illegal reads and writes can occur. (6) Implementation note: to get the same results in the interior between this function and pixConvolve(), it is necessary to add 0.5 for roundoff in the main loop that runs over all pixels. However, if we do that and have white (255) pixels near the image boundary, some overflow occurs for pixels very close to the boundary. We can't fix this by subtracting from the normalized values for the boundary pixels, because this results in underflow if the boundary pixels are black (0). Empirically, adding 0.25 (instead of 0.5) before truncating in the main loop will not cause overflow, but this gives some off-by-1-level errors in interior pixel values. So we add 0.5 for roundoff in the main loop, and for pixels within a half filter width of the boundary, use a L_MIN of the computed value and 255 to avoid overflow during normalization.
Definition at line 81 of file convolvelow.c.
References GET_DATA_BYTE, L_ERROR, L_MAX, L_MIN, PROCNAME, and SET_DATA_BYTE.
Referenced by pixBlockconvGray().
void blockconvAccumLow | ( | l_uint32 * | datad, |
l_int32 | w, | ||
l_int32 | h, | ||
l_int32 | wpld, | ||
l_uint32 * | datas, | ||
l_int32 | d, | ||
l_int32 | wpls | ||
) |
Definition at line 222 of file convolvelow.c.
References GET_DATA_BIT, GET_DATA_BYTE, L_ERROR, and PROCNAME.
Referenced by pixBlockconvAccum().
void blocksumLow | ( | l_uint32 * | datad, |
l_int32 | w, | ||
l_int32 | h, | ||
l_int32 | wpl, | ||
l_uint32 * | dataa, | ||
l_int32 | wpla, | ||
l_int32 | wc, | ||
l_int32 | hc | ||
) |
Input: datad (of 8 bpp dest) w, h, wpl (of 8 bpp dest) dataa (of 32 bpp accum) wpla (of 32 bpp accum) wc, hc (convolution "half-width" and "half-height") Return: void
Notes: (1) The full width and height of the convolution kernel are (2 * wc + 1) and (2 * hc + 1). (2) The lack of symmetry between the handling of the first (hc + 1) lines and the last (hc) lines, and similarly with the columns, is due to fact that for the pixel at (x,y), the accumulator values are taken at (x + wc, y + hc), (x - wc - 1, y + hc), (x + wc, y - hc - 1) and (x - wc - 1, y - hc - 1). (3) Compute sums of ON pixels within the block filter size, normalized between 0 and 255, as if there were no reduced area at the boundary. This under-estimates the value of the boundary pixels, so we multiply them by another normalization factor that is greater than 1. (4) This second normalization is done first for the first hc + 1 lines; then for the last hc lines; and finally for the first wc + 1 and last wc columns in the intermediate lines. (5) The caller should verify that wc < w and hc < h. Under those conditions, illegal reads and writes can occur.
Definition at line 354 of file convolvelow.c.
References GET_DATA_BYTE, L_ERROR, L_MAX, L_MIN, PROCNAME, and SET_DATA_BYTE.
Referenced by pixBlocksum().