|
| static l_int32 * | iaaGetLinearTRC (l_int32 **iaa, l_int32 diff) |
| |
| PIX * | pixCleanBackgroundToWhite (PIX *pixs, PIX *pixim, PIX *pixg, l_float32 gamma, l_int32 blackval, l_int32 whiteval) |
| |
| PIX * | pixBackgroundNormSimple (PIX *pixs, PIX *pixim, PIX *pixg) |
| |
| PIX * | pixBackgroundNorm (PIX *pixs, PIX *pixim, PIX *pixg, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, l_int32 bgval, l_int32 smoothx, l_int32 smoothy) |
| |
| PIX * | pixBackgroundNormMorph (PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, l_int32 bgval) |
| |
| l_int32 | pixBackgroundNormGrayArray (PIX *pixs, PIX *pixim, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, l_int32 bgval, l_int32 smoothx, l_int32 smoothy, PIX **ppixd) |
| |
| l_int32 | pixBackgroundNormRGBArrays (PIX *pixs, PIX *pixim, PIX *pixg, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, l_int32 bgval, l_int32 smoothx, l_int32 smoothy, PIX **ppixr, PIX **ppixg, PIX **ppixb) |
| |
| l_int32 | pixBackgroundNormGrayArrayMorph (PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, l_int32 bgval, PIX **ppixd) |
| |
| l_int32 | pixBackgroundNormRGBArraysMorph (PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, l_int32 bgval, PIX **ppixr, PIX **ppixg, PIX **ppixb) |
| |
| l_int32 | pixGetBackgroundGrayMap (PIX *pixs, PIX *pixim, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, PIX **ppixd) |
| |
| l_int32 | pixGetBackgroundRGBMap (PIX *pixs, PIX *pixim, PIX *pixg, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, PIX **ppixmr, PIX **ppixmg, PIX **ppixmb) |
| |
| l_int32 | pixGetBackgroundGrayMapMorph (PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, PIX **ppixm) |
| |
| l_int32 | pixGetBackgroundRGBMapMorph (PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, PIX **ppixmr, PIX **ppixmg, PIX **ppixmb) |
| |
| l_int32 | pixFillMapHoles (PIX *pix, l_int32 nx, l_int32 ny, l_int32 filltype) |
| |
| PIX * | pixExtendByReplication (PIX *pixs, l_int32 addw, l_int32 addh) |
| |
| l_int32 | pixSmoothConnectedRegions (PIX *pixs, PIX *pixm, l_int32 factor) |
| |
| PIX * | pixGetInvBackgroundMap (PIX *pixs, l_int32 bgval, l_int32 smoothx, l_int32 smoothy) |
| |
| PIX * | pixApplyInvBackgroundGrayMap (PIX *pixs, PIX *pixm, l_int32 sx, l_int32 sy) |
| |
| PIX * | pixApplyInvBackgroundRGBMap (PIX *pixs, PIX *pixmr, PIX *pixmg, PIX *pixmb, l_int32 sx, l_int32 sy) |
| |
| PIX * | pixApplyVariableGrayMap (PIX *pixs, PIX *pixg, l_int32 target) |
| |
| PIX * | pixGlobalNormRGB (PIX *pixd, PIX *pixs, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 mapval) |
| |
| PIX * | pixGlobalNormNoSatRGB (PIX *pixd, PIX *pixs, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 factor, l_float32 rank) |
| |
| l_int32 | pixThresholdSpreadNorm (PIX *pixs, l_int32 filtertype, l_int32 edgethresh, l_int32 smoothx, l_int32 smoothy, l_float32 gamma, l_int32 minval, l_int32 maxval, l_int32 targetthresh, PIX **ppixth, PIX **ppixb, PIX **ppixd) |
| |
| PIX * | pixBackgroundNormFlex (PIX *pixs, l_int32 sx, l_int32 sy, l_int32 smoothx, l_int32 smoothy, l_int32 delta) |
| |
| PIX * | pixContrastNorm (PIX *pixd, PIX *pixs, l_int32 sx, l_int32 sy, l_int32 mindiff, l_int32 smoothx, l_int32 smoothy) |
| |
| l_int32 | pixMinMaxTiles (PIX *pixs, l_int32 sx, l_int32 sy, l_int32 mindiff, l_int32 smoothx, l_int32 smoothy, PIX **ppixmin, PIX **ppixmax) |
| |
| l_int32 | pixSetLowContrast (PIX *pixs1, PIX *pixs2, l_int32 mindiff) |
| |
| PIX * | pixLinearTRCTiled (PIX *pixd, PIX *pixs, l_int32 sx, l_int32 sy, PIX *pixmin, PIX *pixmax) |
| |
pixApplyVariableGrayMap()
Input: pixs (8 bpp)
pixg (8 bpp, variable map)
target (typ. 128 for threshold)
Return: pixd (8 bpp), or null on error
Notes: (1) Suppose you have an image that you want to transform based on some photometric measurement at each point, such as the threshold value for binarization. Representing the photometric measurement as an image pixg, you can threshold in input image using pixVarThresholdToBinary(). Alternatively, you can map the input image pointwise so that the threshold over the entire image becomes a constant, such as 128. For example, if a pixel in pixg is 150 and the target is 128, the corresponding pixel in pixs is mapped linearly to a value (128/150) of the input value. If the resulting mapped image pixd were then thresholded at 128, you would obtain the same result as a direct binarization using pixg with pixVarThresholdToBinary(). (2) The sizes of pixs and pixg must be equal.
pixBackgroundNorm()
Input: pixs (8 bpp grayscale or 32 bpp rgb)
pixim (<optional> 1 bpp 'image' mask; can be null)
pixg (<optional> 8 bpp grayscale version; can be null)
sx, sy (tile size in pixels)
thresh (threshold for determining foreground)
mincount (min threshold on counts in a tile)
bgval (target bg val; typ. > 128)
smoothx (half-width of block convolution kernel width)
smoothy (half-width of block convolution kernel height)
Return: pixd (8 bpp or 32 bpp rgb), or null on error
Notes: (1) This is a top-level interface for normalizing the image intensity by mapping the image so that the background is near the input value 'bgval'. (2) The input image is either grayscale or rgb. (3) For each component in the input image, the background value in each tile is estimated using the values in the tile that are not part of the foreground, where the foreground is determined by the input 'thresh' argument. (4) An optional binary mask can be specified, with the foreground pixels typically over image regions. The resulting background map values will be determined by surrounding pixels that are not under the mask foreground. The origin (0,0) of this mask is assumed to be aligned with the origin of the input image. This binary mask must not fully cover pixs, because then there will be no pixels in the input image available to compute the background. (5) An optional grayscale version of the input pixs can be supplied. The only reason to do this is if the input is RGB and this grayscale version can be used elsewhere. If the input is RGB and this is not supplied, it is made internally using only the green component, and destroyed after use. (6) The dimensions of the pixel tile (sx, sy) give the amount by by which the map is reduced in size from the input image. (7) The threshold is used to binarize the input image, in order to locate the foreground components. If this is set too low, some actual foreground may be used to determine the maps; if set too high, there may not be enough background to determine the map values accurately. Typically, it's better to err by setting the threshold too high. (8) A 'mincount' threshold is a minimum count of pixels in a tile for which a background reading is made, in order for that pixel in the map to be valid. This number should perhaps be at least 1/3 the size of the tile. (9) A 'bgval' target background value for the normalized image. This should be at least 128. If set too close to 255, some clipping will occur in the result. (10) Two factors, 'smoothx' and 'smoothy', are input for smoothing the map. Each low-pass filter kernel dimension is is 2 * (smoothing factor) + 1, so a value of 0 means no smoothing. A value of 1 or 2 is recommended.
pixBackgroundNormFlex()
Input: pixs (8 bpp grayscale; not colormapped)
sx, sy (desired tile dimensions; actual size may vary; use
values between 3 and 10)
smoothx, smoothy (half-width of convolution kernel applied to
threshold array: use values between 1 and 3)
delta (difference parameter in basin filling; use 0
to skip)
Return: pixd (8 bpp, background-normalized), or null on error)
Notes: (1) This does adaptation flexibly to a quickly varying background. For that reason, all input parameters should be small. (2) sx and sy give the tile size; they should be in [5 - 7]. (3) The full width and height of the convolution kernel are (2 * smoothx + 1) and (2 * smoothy + 1). They should be in [1 - 2]. (4) Basin filling is used to fill the large fg regions. The parameter @delta measures the height that the black background is raised from the local minima. By raising the background, it is possible to threshold the large fg regions to foreground. If @delta is too large, bg regions will be lifted, causing thickening of the fg regions. Use 0 to skip.
pixBackgroundNormMorph()
Input: pixs (8 bpp grayscale or 32 bpp rgb)
pixim (<optional> 1 bpp 'image' mask; can be null)
reduction (at which morph closings are done; between 2 and 16)
size (of square Sel for the closing; use an odd number)
bgval (target bg val; typ. > 128)
Return: pixd (8 bpp), or null on error
Notes: (1) This is a top-level interface for normalizing the image intensity by mapping the image so that the background is near the input value 'bgval'. (2) The input image is either grayscale or rgb. (3) For each component in the input image, the background value is estimated using a grayscale closing; hence the 'Morph' in the function name. (4) An optional binary mask can be specified, with the foreground pixels typically over image regions. The resulting background map values will be determined by surrounding pixels that are not under the mask foreground. The origin (0,0) of this mask is assumed to be aligned with the origin of the input image. This binary mask must not fully cover pixs, because then there will be no pixels in the input image available to compute the background. (5) The map is computed at reduced size (given by 'reduction') from the input pixs and optional pixim. At this scale, pixs is closed to remove the background, using a square Sel of odd dimension. The product of reduction * size should be large enough to remove most of the text foreground. (6) No convolutional smoothing needs to be done on the map before inverting it. (7) A 'bgval' target background value for the normalized image. This should be at least 128. If set too close to 255, some clipping will occur in the result.
pixContrastNorm()
Input: pixd (<optional> 8 bpp; null or equal to pixs)
pixs (8 bpp grayscale; not colormapped)
sx, sy (tile dimensions)
mindiff (minimum difference to accept as valid)
smoothx, smoothy (half-width of convolution kernel applied to
min and max arrays: use 0 for no smoothing)
Return: pixd always
Notes: (1) This function adaptively attempts to expand the contrast to the full dynamic range in each tile. If the contrast in a tile is smaller than @mindiff, it uses the min and max pixel values from neighboring tiles. It also can use convolution to smooth the min and max values from neighboring tiles. After all that processing, it is possible that the actual pixel values in the tile are outside the computed [min ... max] range for local contrast normalization. Such pixels are taken to be at either 0 (if below the min) or 255 (if above the max). (2) pixd can be equal to pixs (in-place operation) or null (makes a new pixd). (3) sx and sy give the tile size; they are typically at least 20. (4) mindiff is used to eliminate results for tiles where it is likely that either fg or bg is missing. A value around 50 or more is reasonable. (5) The full width and height of the convolution kernel are (2 * smoothx + 1) and (2 * smoothy + 1). Some smoothing is typically useful, and we limit the smoothing half-widths to the range from 0 to 8. (6) A linear TRC (gamma = 1.0) is applied to increase the contrast in each tile. The result can subsequently be globally corrected, by applying pixGammaTRC() with arbitrary values of gamma and the 0 and 255 points of the mapping.
pixFillMapHoles()
Input: pix (8 bpp; a map, with one pixel for each tile in
a larger image)
nx (number of horizontal pixel tiles that are entirely
covered with pixels in the original source image)
ny (ditto for the number of vertical pixel tiles)
filltype (L_FILL_WHITE or L_FILL_BLACK)
Return: 0 if OK, 1 on error
Notes: (1) This is an in-place operation on pix (the map). pix is typically a low-resolution version of some other image from which it was derived, where each pixel in pix corresponds to a rectangular tile (say, m x n) of pixels in the larger image. All we need to know about the larger image is whether or not the rightmost column and bottommost row of pixels in pix correspond to tiles that are only partially covered by pixels in the larger image. (2) Typically, some number of pixels in the input map are not known, and their values must be determined by near pixels that are known. These unknown pixels are the 'holes'. They can take on only two values, 0 and 255, and the instruction about which to fill is given by the filltype flag. (3) The "holes" can come from two sources. The first is when there are not enough foreground or background pixels in a tile; the second is when a tile is at least partially covered by an image mask. If we're filling holes in a fg mask, the holes are initialized to black (0) and use L_FILL_BLACK. For filling holes in a bg mask, initialize the holes to white (255) and use L_FILL_WHITE. (4) If w is the map width, nx = w or nx = w - 1; ditto for h and ny.
pixGetBackgroundRGBMap()
Input: pixs (32 bpp rgb)
pixim (<optional> 1 bpp 'image' mask; can be null; it
should not have all foreground pixels)
pixg (<optional> 8 bpp grayscale version; can be null)
sx, sy (tile size in pixels)
thresh (threshold for determining foreground)
mincount (min threshold on counts in a tile)
&pixmr, &pixmg, &pixmb (<return> rgb maps)
Return: 0 if OK, 1 on error
Notes: (1) If pixg, which is a grayscale version of pixs, is provided, use this internally to generate the foreground mask. Otherwise, a grayscale version of pixs will be generated from the green component only, used, and destroyed.
pixGlobalNormNoSatRGB()
Input: pixd (<optional> null, existing or equal to pixs)
pixs (32 bpp rgb)
rval, gval, bval (pixel values in pixs that are
linearly mapped to mapval; but see below)
factor (subsampling factor; integer >= 1)
rank (between 0.0 and 1.0; typ. use a value near 1.0)
Return: pixd (32 bpp rgb), or null on error
Notes: (1) This is a version of pixGlobalNormRGB(), where the output intensity is scaled back so that a controlled fraction of pixel components is allowed to saturate. See comments in pixGlobalNormRGB(). (2) The value of pixd determines if the results are written to a new pix (use NULL), in-place to pixs (use pixs), or to some other existing pix. (3) This does a global normalization of an image where the r,g,b color components are not balanced. Thus, white in pixs is represented by a set of r,g,b values that are not all 255. (4) The input values (rval, gval, bval) can be chosen to be the color that, after normalization, becomes white background. For images that are mostly background, the closer these values are to the median component values, the closer the resulting background will be to gray, becoming white at the brightest places. (5) The mapval used in pixGlobalNormRGB() is computed here to avoid saturation of any component in the image (save for a fraction of the pixels given by the input rank value).
pixGlobalNormRGB()
Input: pixd (<optional> null, existing or equal to pixs)
pixs (32 bpp rgb, or colormapped)
rval, gval, bval (pixel values in pixs that are
linearly mapped to mapval)
mapval (use 255 for mapping to white)
Return: pixd (32 bpp rgb or colormapped), or null on error
Notes: (1) The value of pixd determines if the results are written to a new pix (use NULL), in-place to pixs (use pixs), or to some other existing pix. (2) This does a global normalization of an image where the r,g,b color components are not balanced. Thus, white in pixs is represented by a set of r,g,b values that are not all 255. (3) The input values (rval, gval, bval) should be chosen to represent the gray color (mapval, mapval, mapval) in src. Thus, this function will map (rval, gval, bval) to that gray color. (4) Typically, mapval = 255, so that (rval, gval, bval) corresponds to the white point of src. In that case, these parameters should be chosen so that few pixels have higher values. (5) In all cases, we do a linear TRC separately on each of the components, saturating at 255. (6) If the input pix is 8 bpp without a colormap, you can get this functionality with mapval = 255 by calling: pixGammaTRC(pixd, pixs, 1.0, 0, bgval); where bgval is the value you want to be mapped to 255. Or more generally, if you want bgval to be mapped to mapval: pixGammaTRC(pixd, pixs, 1.0, 0, 255 * bgval / mapval);
pixSmoothConnectedRegions()
Input: pixs (8 bpp grayscale; no colormap)
pixm (<optional> 1 bpp; if null, this is a no-op)
factor (subsampling factor for getting average; >= 1)
Return: 0 if OK, 1 on error
Notes: (1) The pixels in pixs corresponding to those in each 8-connected region in the mask are set to the average value. (2) This is required for adaptive mapping to avoid the generation of stripes in the background map, due to variations in the pixel values near the edges of mask regions. (3) This function is optimized for background smoothing, where there are a relatively small number of components. It will be inefficient if used where there are many small components.
| l_int32 pixThresholdSpreadNorm |
( |
PIX * |
pixs, |
|
|
l_int32 |
filtertype, |
|
|
l_int32 |
edgethresh, |
|
|
l_int32 |
smoothx, |
|
|
l_int32 |
smoothy, |
|
|
l_float32 |
gamma, |
|
|
l_int32 |
minval, |
|
|
l_int32 |
maxval, |
|
|
l_int32 |
targetthresh, |
|
|
PIX ** |
ppixth, |
|
|
PIX ** |
ppixb, |
|
|
PIX ** |
ppixd |
|
) |
| |
pixThresholdSpreadNorm()
Input: pixs (8 bpp grayscale; not colormapped)
filtertype (L_SOBEL_EDGE or L_TWO_SIDED_EDGE);
edgethresh (threshold on magnitude of edge filter; typ 10-20)
smoothx, smoothy (half-width of convolution kernel applied to
spread threshold: use 0 for no smoothing)
gamma (gamma correction; typ. about 0.7)
minval (input value that gives 0 for output; typ. -25)
maxval (input value that gives 255 for output; typ. 255)
targetthresh (target threshold for normalization)
&pixth (<optional return> computed local threshold value)
&pixb (<optional return> thresholded normalized image)
&pixd (<optional return> normalized image)
Return: 0 if OK, 1 on error
Notes: (1) The basis of this approach is the use of seed spreading on a (possibly) sparse set of estimates for the local threshold. The resulting dense estimates are smoothed by convolution and used to either threshold the input image or normalize it with a local transformation that linearly maps the pixels so that the local threshold estimate becomes constant over the resulting image. This approach is one of several that have been suggested (and implemented) by Ray Smith. (2) You can use either the Sobel or TwoSided edge filters. The results appear to be similar, using typical values of edgethresh in the rang 10-20. (3) To skip the trc enhancement, use gamma = 1.0, minval = 0 and maxval = 255. (4) For the normalized image pixd, each pixel is linearly mapped in such a way that the local threshold is equal to targetthresh. (5) The full width and height of the convolution kernel are (2 * smoothx + 1) and (2 * smoothy + 1). (6) This function can be used with the pixtiling utility if the images are too large. See pixOtsuAdaptiveThreshold() for an example of this.