Leptonica  1.83.1
Image processing and image analysis suite
pix3.c File Reference
#include <string.h>
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Macros

#define EQUAL_SIZE_WARNING   0
 

Functions

static BOXAfindTileRegionsForSearch (BOX *box, l_int32 w, l_int32 h, l_int32 searchdir, l_int32 mindist, l_int32 tsize, l_int32 ntiles)
 
l_ok pixSetMasked (PIX *pixd, PIX *pixm, l_uint32 val)
 
l_ok pixSetMaskedGeneral (PIX *pixd, PIX *pixm, l_uint32 val, l_int32 x, l_int32 y)
 
l_ok pixCombineMasked (PIX *pixd, PIX *pixs, PIX *pixm)
 
l_ok pixCombineMaskedGeneral (PIX *pixd, PIX *pixs, PIX *pixm, l_int32 x, l_int32 y)
 
l_ok pixPaintThroughMask (PIX *pixd, PIX *pixm, l_int32 x, l_int32 y, l_uint32 val)
 
PIXpixCopyWithBoxa (PIX *pixs, BOXA *boxa, l_int32 background)
 
l_ok pixPaintSelfThroughMask (PIX *pixd, PIX *pixm, l_int32 x, l_int32 y, l_int32 searchdir, l_int32 mindist, l_int32 tilesize, l_int32 ntiles, l_int32 distblend)
 
PIXpixMakeMaskFromVal (PIX *pixs, l_int32 val)
 
PIXpixMakeMaskFromLUT (PIX *pixs, l_int32 *tab)
 
PIXpixMakeArbMaskFromRGB (PIX *pixs, l_float32 rc, l_float32 gc, l_float32 bc, l_float32 thresh)
 
PIXpixSetUnderTransparency (PIX *pixs, l_uint32 val, l_int32 debug)
 
PIXpixMakeAlphaFromMask (PIX *pixs, l_int32 dist, BOX **pbox)
 
l_ok pixGetColorNearMaskBoundary (PIX *pixs, PIX *pixm, BOX *box, l_int32 dist, l_uint32 *pval, l_int32 debug)
 
PIXpixDisplaySelectedPixels (PIX *pixs, PIX *pixm, SEL *sel, l_uint32 val)
 
PIXpixInvert (PIX *pixd, PIX *pixs)
 
PIXpixOr (PIX *pixd, PIX *pixs1, PIX *pixs2)
 
PIXpixAnd (PIX *pixd, PIX *pixs1, PIX *pixs2)
 
PIXpixXor (PIX *pixd, PIX *pixs1, PIX *pixs2)
 
PIXpixSubtract (PIX *pixd, PIX *pixs1, PIX *pixs2)
 
l_ok pixZero (PIX *pix, l_int32 *pempty)
 
l_ok pixForegroundFraction (PIX *pix, l_float32 *pfract)
 
NUMApixaCountPixels (PIXA *pixa)
 
l_ok pixCountPixels (PIX *pixs, l_int32 *pcount, l_int32 *tab8)
 
l_ok pixCountPixelsInRect (PIX *pixs, BOX *box, l_int32 *pcount, l_int32 *tab8)
 
NUMApixCountByRow (PIX *pix, BOX *box)
 
NUMApixCountByColumn (PIX *pix, BOX *box)
 
NUMApixCountPixelsByRow (PIX *pix, l_int32 *tab8)
 
NUMApixCountPixelsByColumn (PIX *pix)
 
l_ok pixCountPixelsInRow (PIX *pix, l_int32 row, l_int32 *pcount, l_int32 *tab8)
 
NUMApixGetMomentByColumn (PIX *pix, l_int32 order)
 
l_ok pixThresholdPixelSum (PIX *pix, l_int32 thresh, l_int32 *pabove, l_int32 *tab8)
 
l_int32 * makePixelSumTab8 (void)
 
l_int32 * makePixelCentroidTab8 (void)
 
NUMApixAverageByRow (PIX *pix, BOX *box, l_int32 type)
 
NUMApixAverageByColumn (PIX *pix, BOX *box, l_int32 type)
 
l_ok pixAverageInRect (PIX *pixs, PIX *pixm, BOX *box, l_int32 minval, l_int32 maxval, l_int32 subsamp, l_float32 *pave)
 
l_ok pixAverageInRectRGB (PIX *pixs, PIX *pixm, BOX *box, l_int32 subsamp, l_uint32 *pave)
 
NUMApixVarianceByRow (PIX *pix, BOX *box)
 
NUMApixVarianceByColumn (PIX *pix, BOX *box)
 
l_ok pixVarianceInRect (PIX *pix, BOX *box, l_float32 *prootvar)
 
NUMApixAbsDiffByRow (PIX *pix, BOX *box)
 
NUMApixAbsDiffByColumn (PIX *pix, BOX *box)
 
l_ok pixAbsDiffInRect (PIX *pix, BOX *box, l_int32 dir, l_float32 *pabsdiff)
 
l_ok pixAbsDiffOnLine (PIX *pix, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_float32 *pabsdiff)
 
l_int32 pixCountArbInRect (PIX *pixs, BOX *box, l_int32 val, l_int32 factor, l_int32 *pcount)
 
PIXpixMirroredTiling (PIX *pixs, l_int32 w, l_int32 h)
 
l_ok pixFindRepCloseTile (PIX *pixs, BOX *box, l_int32 searchdir, l_int32 mindist, l_int32 tsize, l_int32 ntiles, BOX **pboxtile, l_int32 debug)
 

Detailed Description


   This file has these operations:

     (1) Mask-directed operations
     (2) Full-image bit-logical operations
     (3) Foreground pixel counting operations on 1 bpp images
     (4) Average and variance of pixel values
     (5) Mirrored tiling of a smaller image


   Masked operations
          l_int32     pixSetMasked()
          l_int32     pixSetMaskedGeneral()
          l_int32     pixCombineMasked()
          l_int32     pixCombineMaskedGeneral()
          l_int32     pixPaintThroughMask()
          l_int32     pixCopyWithBoxa()  -- this is boxa-directed
          PIX        *pixPaintSelfThroughMask()
          PIX        *pixMakeMaskFromVal()
          PIX        *pixMakeMaskFromLUT()
          PIX        *pixMakeArbMaskFromRGB()
          PIX        *pixSetUnderTransparency()
          PIX        *pixMakeAlphaFromMask()
          l_int32     pixGetColorNearMaskBoundary()
          PIX        *pixDisplaySelectedPixels()  -- for debugging

   One and two-image boolean operations on arbitrary depth images
          PIX        *pixInvert()
          PIX        *pixOr()
          PIX        *pixAnd()
          PIX        *pixXor()
          PIX        *pixSubtract()

   Foreground pixel counting in 1 bpp images
          l_int32     pixZero()
          l_int32     pixForegroundFraction()
          NUMA       *pixaCountPixels()
          l_int32     pixCountPixels()
          l_int32     pixCountPixelsInRect()
          NUMA       *pixCountByRow()
          NUMA       *pixCountByColumn()
          NUMA       *pixCountPixelsByRow()
          NUMA       *pixCountPixelsByColumn()
          l_int32     pixCountPixelsInRow()
          NUMA       *pixGetMomentByColumn()
          l_int32     pixThresholdPixelSum()
          l_int32    *makePixelSumTab8()
          l_int32    *makePixelCentroidTab8()

   Average of pixel values in gray images
          NUMA       *pixAverageByRow()
          NUMA       *pixAverageByColumn()
          l_int32     pixAverageInRect()

   Average of pixel values in RGB images
          l_int32     pixAverageInRectRGB()

   Variance of pixel values in gray images
          NUMA       *pixVarianceByRow()
          NUMA       *pixVarianceByColumn()
          l_int32     pixVarianceInRect()

   Average of absolute value of pixel differences in gray images
          NUMA       *pixAbsDiffByRow()
          NUMA       *pixAbsDiffByColumn()
          l_int32     pixAbsDiffInRect()
          l_int32     pixAbsDiffOnLine()

   Count of pixels with specific value
          l_int32     pixCountArbInRect()

   Mirrored tiling
          PIX        *pixMirroredTiling()

   Representative tile near but outside region
          l_int32     pixFindRepCloseTile()

   Static helper function
          static BOXA    *findTileRegionsForSearch()

Definition in file pix3.c.

Function Documentation

◆ findTileRegionsForSearch()

static BOXA * findTileRegionsForSearch ( BOX box,
l_int32  w,
l_int32  h,
l_int32  searchdir,
l_int32  mindist,
l_int32  tsize,
l_int32  ntiles 
)
static

findTileRegionsForSearch()

Parameters
[in]boxregion of Pix to search around
[in]w,hdimensions of Pix
[in]searchdirL_HORIZ or L_VERT; direction to search
[in]mindistmin distance of selected tile edge from box; >= 0
[in]tsizetile size; > 1; even; typically ~50
[in]ntilesnumber of tiles tested in each row/column
Returns
boxa if OK, or NULL on error
Notes:
     (1) See calling function pixfindRepCloseTile().

Definition at line 3561 of file pix3.c.

References boxGetGeometry().

◆ makePixelCentroidTab8()

l_int32* makePixelCentroidTab8 ( void  )

makePixelCentroidTab8()

Returns
table of 256 l_int32.
Notes:
     (1) This table of integers gives the centroid weight of the 1 bits
         in the 8 bit index.  In other words, if sumtab is obtained by
         makePixelSumTab8, and centroidtab is obtained by
         makePixelCentroidTab8, then, for 1 <= i <= 255,
         centroidtab[i] / (float)sumtab[i]
         is the centroid of the 1 bits in the 8-bit index i, where the
         MSB is considered to have position 0 and the LSB is considered
         to have position 7.

Definition at line 2394 of file pix3.c.

Referenced by pixaAccumulateSamples(), pixaCentroids(), pixCentroid(), and pixCompareWithTranslation().

◆ makePixelSumTab8()

l_int32* makePixelSumTab8 ( void  )

◆ pixAbsDiffByColumn()

NUMA* pixAbsDiffByColumn ( PIX pix,
BOX box 
)

pixAbsDiffByColumn()

Parameters
[in]pix8 bpp; no colormap
[in]box[optional] clipping box for region; can be null
Returns
na of abs val pixel difference averages by column, or NULL on error
Notes:
     (1) This is an average over differences of adjacent pixels along
         each column.
     (2) To resample for a bin size different from 1, use
         numaUniformSampling() on the result of this function.

Definition at line 3042 of file pix3.c.

◆ pixAbsDiffByRow()

NUMA* pixAbsDiffByRow ( PIX pix,
BOX box 
)

pixAbsDiffByRow()

Parameters
[in]pix8 bpp; no colormap
[in]box[optional] clipping box for region; can be null
Returns
na of abs val pixel difference averages by row, or NULL on error
Notes:
     (1) This is an average over differences of adjacent pixels along
         each row.
     (2) To resample for a bin size different from 1, use
         numaUniformSampling() on the result of this function.

Definition at line 2983 of file pix3.c.

◆ pixAbsDiffInRect()

l_ok pixAbsDiffInRect ( PIX pix,
BOX box,
l_int32  dir,
l_float32 *  pabsdiff 
)

pixAbsDiffInRect()

Parameters
[in]pix8 bpp; not cmapped
[in]box[optional] if null, use entire image
[in]dirdifferences along L_HORIZONTAL_LINE or L_VERTICAL_LINE
[out]pabsdiffaverage of abs diff pixel values in region
Returns
0 if OK; 1 on error
Notes:
     (1) This gives the average over the abs val of differences of
         adjacent pixels values, along either each
            row:     dir == L_HORIZONTAL_LINE
            column:  dir == L_VERTICAL_LINE

Definition at line 3103 of file pix3.c.

◆ pixAbsDiffOnLine()

l_ok pixAbsDiffOnLine ( PIX pix,
l_int32  x1,
l_int32  y1,
l_int32  x2,
l_int32  y2,
l_float32 *  pabsdiff 
)

pixAbsDiffOnLine()

Parameters
[in]pix8 bpp; not cmapped
[in]x1,y1first point; x1 <= x2, y1 <= y2
[in]x2,y2first point
[out]pabsdiffaverage of abs diff pixel values on line
Returns
0 if OK; 1 on error
Notes:
     (1) This gives the average over the abs val of differences of
         adjacent pixels values, along a line that is either horizontal
         or vertical.
     (2) If horizontal, require x1 < x2; if vertical, require y1 < y2.

Definition at line 3178 of file pix3.c.

◆ pixaCountPixels()

NUMA* pixaCountPixels ( PIXA pixa)

pixaCountPixels()

Parameters
[in]pixaarray of 1 bpp pix
Returns
na of ON pixels in each pix, or NULL on error

Definition at line 1850 of file pix3.c.

References L_CLONE, numaCreate(), pixaGetCount(), and pixaGetPix().

Referenced by pixaSelectByArea().

◆ pixAnd()

PIX* pixAnd ( PIX pixd,
PIX pixs1,
PIX pixs2 
)

pixAnd()

Parameters
[in]pixd[optional]; this can be null, equal to pixs1, different from pixs1
[in]pixs1can be == pixd
[in]pixs2must be != pixd
Returns
pixd always
Notes:
     (1) This gives the intersection of two images with equal depth,
         aligning them to the the UL corner.  pixs1 and pixs2
         need not have the same width and height.
     (2) There are 3 cases:
           (a) pixd == null,   (src1 & src2) --> new pixd
           (b) pixd == pixs1,  (src1 & src2) --> src1  (in-place)
           (c) pixd != pixs1,  (src1 & src2) --> input pixd
     (3) For clarity, if the case is known, use these patterns:
           (a) pixd = pixAnd(NULL, pixs1, pixs2);
           (b) pixAnd(pixs1, pixs1, pixs2);
           (c) pixAnd(pixd, pixs1, pixs2);
     (4) The size of the result is determined by pixs1.
     (5) The depths of pixs1 and pixs2 must be equal.
     (6) Note carefully that the order of pixs1 and pixs2 only matters
         for the in-place case.  For in-place, you must have
         pixd == pixs1.  Setting pixd == pixs2 gives an incorrect
         result: the copy puts pixs1 image data in pixs2, and
         the rasterop is then between pixs2 and pixs2 (a no-op).

Definition at line 1592 of file pix3.c.

Referenced by boxaCompareRegions(), pixaClipToPix(), pixCorrelationBinary(), and pixDisplayDiffBinary().

◆ pixAverageByColumn()

NUMA* pixAverageByColumn ( PIX pix,
BOX box,
l_int32  type 
)

pixAverageByColumn()

Parameters
[in]pix8 or 16 bpp; no colormap
[in]box[optional] clipping box for sum; can be null
[in]typeL_WHITE_IS_MAX, L_BLACK_IS_MAX
Returns
na of pixel averages by column, or NULL on error
Notes:
     (1) To resample for a bin size different from 1, use
         numaUniformSampling() on the result of this function.
     (2) If type == L_BLACK_IS_MAX, black pixels get the maximum
         value (0xff for 8 bpp, 0xffff for 16 bpp) and white get 0.

Definition at line 2514 of file pix3.c.

References L_BLACK_IS_MAX, L_WHITE_IS_MAX, and pixGetDimensions().

◆ pixAverageByRow()

NUMA* pixAverageByRow ( PIX pix,
BOX box,
l_int32  type 
)

pixAverageByRow()

Parameters
[in]pix8 or 16 bpp; no colormap
[in]box[optional] clipping box for sum; can be null
[in]typeL_WHITE_IS_MAX, L_BLACK_IS_MAX
Returns
na of pixel averages by row, or NULL on error
Notes:
     (1) To resample for a bin size different from 1, use
         numaUniformSampling() on the result of this function.
     (2) If type == L_BLACK_IS_MAX, black pixels get the maximum
         value (0xff for 8 bpp, 0xffff for 16 bpp) and white get 0.

Definition at line 2447 of file pix3.c.

References L_BLACK_IS_MAX, L_WHITE_IS_MAX, and pixGetDimensions().

◆ pixAverageInRect()

l_ok pixAverageInRect ( PIX pixs,
PIX pixm,
BOX box,
l_int32  minval,
l_int32  maxval,
l_int32  subsamp,
l_float32 *  pave 
)

pixAverageInRect()

Parameters
[in]pixs1, 2, 4, 8 bpp; not cmapped
[in]pixm[optional] 1 bpp mask; if null, use all pixels
[in]box[optional] if null, use entire image
[in]minvalignore values less than this
[in]maxvalignore values greater than this
[in]subsampsubsample factor: integer; use 1 for all pixels
[out]paveaverage of pixel values under consideration
Returns
0 if OK; 1 on error; 2 if all pixels are filtered out
Notes:
     (1) The average is computed with 4 optional filters: a rectangle,
         a mask, a contiguous set of range values, and subsampling.
         In practice you might use only one or two of these.
     (2) The mask pixm is a blocking mask: only count pixels in the bg.
         If it exists, alignment is assumed at UL corner and computation
         is over the minimum intersection of pixs and pixm.
         If you want the average of pixels under the mask fg, invert it.
     (3) Set the range limits minval = 0 and maxval = 255 to use
         all non-masked pixels (regardless of value) in the average.
     (4) If no pixels are used in the averaging, the returned average
         value is 0 and the function returns 2.  This is not an error,
         but it says to disregard the returned average value.
     (5) For example, to average all pixels in a given clipping rect box,
             pixAverageInRect(pixs, NULL, box, 0, 255, 1, &aveval);

Definition at line 2599 of file pix3.c.

◆ pixAverageInRectRGB()

l_ok pixAverageInRectRGB ( PIX pixs,
PIX pixm,
BOX box,
l_int32  subsamp,
l_uint32 *  pave 
)

pixAverageInRectRGB()

Parameters
[in]pixsrgb; not cmapped
[in]pixm[optional] 1 bpp mask; if null, use all pixels
[in]box[optional] if null, use entire image
[in]subsampsubsample factor: integer; use 1 for all pixels
[out]paveaverage color of pixel values under consideration, in format 0xrrggbb00.
Returns
0 if OK; 1 on error; 2 if all pixels are filtered out
Notes:
     (1) The average is computed with 3 optional filters: a rectangle,
         a mask, and subsampling.
         In practice you might use only one or two of these.
     (2) The mask pixm is a blocking mask: only count pixels in the bg.
         If it exists, alignment is assumed at UL corner and computation
         is over the minimum intersection of pixs and pixm.
         If you want the average of pixels under the mask fg, invert it.
     (3) If no pixels are used in the averaging, the returned average
         value is 0 and the function returns 2.  This is not an error,
         but it says to disregard the returned average value.
     (4) For example, to average all pixels in a given clipping rect box,
             pixAverageInRectRGB(pixs, NULL, box, 1, &aveval);

Definition at line 2704 of file pix3.c.

◆ pixCombineMasked()

l_ok pixCombineMasked ( PIX pixd,
PIX pixs,
PIX pixm 
)

pixCombineMasked()

Parameters
[in]pixd1 bpp, 8 bpp gray or 32 bpp rgb; no cmap
[in]pixs1 bpp, 8 bpp gray or 32 bpp rgb; no cmap
[in]pixm[optional] 1 bpp mask; no operation if NULL
Returns
0 if OK; 1 on error
Notes:
     (1) In-place operation; pixd is changed.
     (2) This sets each pixel in pixd that co-locates with an ON
         pixel in pixm to the corresponding value of pixs.
     (3) pixs and pixd must be the same depth and not colormapped.
     (4) All three input pix are aligned at the UL corner, and the
         operation is clipped to the intersection of all three images.
     (5) If pixm == NULL, it's a no-op.
     (6) Implementation: see notes in pixCombineMaskedGeneral().
         For 8 bpp selective masking, you might guess that it
         would be faster to generate an 8 bpp version of pixm,
         using pixConvert1To8(pixm, 0, 255), and then use a
         general combine operation
              d = (d & ~m) | (s & m)
         on a word-by-word basis.  Not always.  The word-by-word
         combine takes a time that is independent of the mask data.
         If the mask is relatively sparse, the byte-check method
         is actually faster!

Definition at line 378 of file pix3.c.

References pixGetDimensions().

Referenced by pixAutoPhotoinvert(), pixMorphSequenceMasked(), and wshedRenderColors().

◆ pixCombineMaskedGeneral()

l_ok pixCombineMaskedGeneral ( PIX pixd,
PIX pixs,
PIX pixm,
l_int32  x,
l_int32  y 
)

pixCombineMaskedGeneral()

Parameters
[in]pixd1 bpp, 8 bpp gray or 32 bpp rgb
[in]pixs1 bpp, 8 bpp gray or 32 bpp rgb
[in]pixm[optional] 1 bpp mask
[in]x,yorigin of pixs and pixm relative to pixd; can be negative
Returns
0 if OK; 1 on error
Notes:
     (1) In-place operation; pixd is changed.
     (2) This is a generalized version of pixCombinedMasked(), where
         the source and mask can be placed at the same (arbitrary)
         location relative to pixd.
     (3) pixs and pixd must be the same depth and not colormapped.
     (4) The UL corners of both pixs and pixm are aligned with
         the point (x, y) of pixd, and the operation is clipped to
         the intersection of all three images.
     (5) If pixm == NULL, it's a no-op.
     (6) Implementation.  There are two ways to do these.  In the first,
         we use rasterop, ORing the part of pixs under the mask
         with pixd (which has been appropriately cleared there first).
         In the second, the mask is used one pixel at a time to
         selectively replace pixels of pixd with those of pixs.
         Here, we use rasterop for 1 bpp and pixel-wise replacement
         for 8 and 32 bpp.  To use rasterop for 8 bpp, for example,
         we must first generate an 8 bpp version of the mask.
         The code is simple:

            Pix *pixm8 = pixConvert1To8(NULL, pixm, 0, 255);
            Pix *pixt = pixAnd(NULL, pixs, pixm8);
            pixRasterop(pixd, x, y, wmin, hmin, PIX_DST & PIX_NOT(PIX_SRC),
                        pixm8, 0, 0);
            pixRasterop(pixd, x, y, wmin, hmin, PIX_SRC | PIX_DST,
                        pixt, 0, 0);
            pixDestroy(&pixt);
            pixDestroy(&pixm8);

Definition at line 495 of file pix3.c.

References pixGetDimensions().

◆ pixCopyWithBoxa()

PIX* pixCopyWithBoxa ( PIX pixs,
BOXA boxa,
l_int32  background 
)

pixCopyWithBoxa()

Parameters
[in]pixsall depths; cmap ok
[in]boxae.g., from components of a photomask
[in]backgroundL_SET_WHITE or L_SET_BLACK
Returns
pixd or NULL on error
Notes:
     (1) Pixels from pixs are copied ("blitted") through each box into pixd.
     (2) Pixels not copied are preset to either white or black.
     (3) This fast and simple implementation can use rasterop because
         each region to be copied is rectangular.
     (4) A much slower implementation that doesn't use rasterop would make
         a 1 bpp mask from the boxa and then copy, pixel by pixel,
         through the mask:
            pixGetDimensions(pixs, &w, &h, NULL);
            pixm = pixCreate(w, h, 1);
            pixm = pixMaskBoxa(pixm, pixm, boxa);
            pixd = pixCreateTemplate(pixs);
            pixSetBlackOrWhite(pixd, background);
            pixCombineMasked(pixd, pixs, pixm);
            pixDestroy(&pixm);

Definition at line 749 of file pix3.c.

References boxaGetBoxGeometry(), boxaGetCount(), L_SET_BLACK, L_SET_WHITE, PIX_SRC, pixCreateTemplate(), pixRasterop(), and pixSetBlackOrWhite().

◆ pixCountArbInRect()

l_int32 pixCountArbInRect ( PIX pixs,
BOX box,
l_int32  val,
l_int32  factor,
l_int32 *  pcount 
)

pixCountArbInRect()

Parameters
[in]pixs1,2,4,8 bpp; can be colormapped
[in]box[optional] over which count is made; use entire image if NULL
[in]valpixel value to count
[in]factorsubsampling factor; integer >= 1
[out]pcountcount; estimate it if factor > 1
Returns
na histogram, or NULL on error
Notes:
     (1) If pixs is cmapped, val is compared to the colormap index;
         otherwise, val is compared to the grayscale value.
     (2) Set the subsampling factor > 1 to reduce the amount of computation.
         If factor > 1, multiply the count by factor * factor.

Definition at line 3258 of file pix3.c.

◆ pixCountByColumn()

NUMA* pixCountByColumn ( PIX pix,
BOX box 
)

pixCountByColumn()

Parameters
[in]pix1 bpp
[in]box[optional] clipping box for count; can be null
Returns
na of number of ON pixels by column, or NULL on error
Notes:
     (1) To resample for a bin size different from 1, use
         numaUniformSampling() on the result of this function.

Definition at line 2052 of file pix3.c.

◆ pixCountByRow()

NUMA* pixCountByRow ( PIX pix,
BOX box 
)

pixCountByRow()

Parameters
[in]pix1 bpp
[in]box[optional] clipping box for count; can be null
Returns
na of number of ON pixels by row, or NULL on error
Notes:
     (1) To resample for a bin size different from 1, use
         numaUniformSampling() on the result of this function.

Definition at line 2002 of file pix3.c.

◆ pixCountPixels()

l_ok pixCountPixels ( PIX pixs,
l_int32 *  pcount,
l_int32 *  tab8 
)

pixCountPixels()

Parameters
[in]pixs1 bpp
[out]pcountcount of ON pixels
[in]tab8[optional] 8-bit pixel lookup table
Returns
0 if OK; 1 on error

Definition at line 1893 of file pix3.c.

Referenced by boxaCompareRegions(), boxaGetCoverage(), evalColorfillData(), pixCompareWithTranslation(), pixCorrelationBinary(), pixFindStrokeLength(), pixFindStrokeWidth(), recogAverageSamples(), recogGetWindowedArea(), and recogTrainingFinished().

◆ pixCountPixelsByColumn()

NUMA* pixCountPixelsByColumn ( PIX pix)

pixCountPixelsByColumn()

Parameters
[in]pix1 bpp
Returns
na of counts in each column, or NULL on error

Definition at line 2128 of file pix3.c.

◆ pixCountPixelsByRow()

NUMA* pixCountPixelsByRow ( PIX pix,
l_int32 *  tab8 
)

pixCountPixelsByRow()

Parameters
[in]pix1 bpp
[in]tab8[optional] 8-bit pixel lookup table
Returns
na of counts, or NULL on error

Definition at line 2096 of file pix3.c.

Referenced by pixFindDifferentialSquareSum(), and pixGetTextBaseline().

◆ pixCountPixelsInRect()

l_ok pixCountPixelsInRect ( PIX pixs,
BOX box,
l_int32 *  pcount,
l_int32 *  tab8 
)

pixCountPixelsInRect()

Parameters
[in]pixs1 bpp
[in]box(can be null)
[out]pcountcount of ON pixels
[in]tab8[optional] 8-bit pixel lookup table
Returns
0 if OK; 1 on error

Definition at line 1955 of file pix3.c.

◆ pixCountPixelsInRow()

l_ok pixCountPixelsInRow ( PIX pix,
l_int32  row,
l_int32 *  pcount,
l_int32 *  tab8 
)

pixCountPixelsInRow()

Parameters
[in]pix1 bpp
[in]rownumber
[out]pcountsum of ON pixels in raster line
[in]tab8[optional] 8-bit pixel lookup table
Returns
0 if OK; 1 on error

Definition at line 2167 of file pix3.c.

◆ pixDisplaySelectedPixels()

PIX* pixDisplaySelectedPixels ( PIX pixs,
PIX pixm,
SEL sel,
l_uint32  val 
)

pixDisplaySelectedPixels()

Parameters
[in]pixs[optional] any depth
[in]pixm1 bpp mask, aligned UL corner with pixs
[in]sel[optional] pattern to paint at each pixel in pixm
[in]valrgb rendering of pattern
Returns
pixd, or NULL on error
Notes:
     (1) For every fg pixel in pixm, this paints the pattern in sel
         in color val on a copy of pixs.
     (2) The implementation is to dilate pixm by sel, and then
         paint through the dilated mask onto pixs.
     (3) If pixs == NULL, it paints on a white image.
     (4) If sel == NULL, it paints only the pixels in the input pixm.
     (5) This visualization would typically be used in debugging.

Definition at line 1427 of file pix3.c.

◆ pixFindRepCloseTile()

l_ok pixFindRepCloseTile ( PIX pixs,
BOX box,
l_int32  searchdir,
l_int32  mindist,
l_int32  tsize,
l_int32  ntiles,
BOX **  pboxtile,
l_int32  debug 
)

pixFindRepCloseTile()

Parameters
[in]pixs32 bpp rgb
[in]boxregion of pixs to search around
[in]searchdirL_HORIZ or L_VERT; direction to search
[in]mindistmin distance of selected tile edge from box; >= 0
[in]tsizetile size; > 1; even; typically ~50
[in]ntilesnumber of tiles tested in each row/column
[out]pboxtileregion of best tile
[in]debug1 for debug output
Returns
0 if OK, 1 on error
Notes:
     (1) This looks for one or two square tiles with conforming median
         intensity and low variance, that is outside but near the input box.
     (2) mindist specifies the gap between the box and the
         potential tiles.  The tiles are given an overlap of 50%.
         ntiles specifies the number of tiles that are tested
         beyond mindist for each row or column.
     (3) For example, if mindist = 20, tilesize = 50 and ntiles = 3,
         a horizontal search to the right will have 3 tiles in each row,
         with left edges at 20, 45 and 70 from the right edge of the
         input box.  The number of rows of tiles is determined by
         the height of box and tsize, with the 50% overlap..

Definition at line 3428 of file pix3.c.

◆ pixForegroundFraction()

l_ok pixForegroundFraction ( PIX pix,
l_float32 *  pfract 
)

pixForegroundFraction()

Parameters
[in]pix1 bpp
[out]pfractfraction of ON pixels
Returns
0 if OK; 1 on error

Definition at line 1825 of file pix3.c.

Referenced by pixAutoPhotoinvert().

◆ pixGetColorNearMaskBoundary()

l_ok pixGetColorNearMaskBoundary ( PIX pixs,
PIX pixm,
BOX box,
l_int32  dist,
l_uint32 *  pval,
l_int32  debug 
)

pixGetColorNearMaskBoundary()

Parameters
[in]pixs32 bpp rgb
[in]pixm1 bpp mask, full image
[in]boxregion of mask; typically b.b. of a component
[in]distdistance into BG from mask boundary to use
[out]pvalaverage pixel value
[in]debug1 to output mask images
Returns
0 if OK, 1 on error.
Notes:
     (1) This finds the average color in a set of pixels that are
         roughly a distance dist from the c.c. boundary and in the
         background of the mask image.

Definition at line 1329 of file pix3.c.

◆ pixGetMomentByColumn()

NUMA* pixGetMomentByColumn ( PIX pix,
l_int32  order 
)

pixGetMomentByColumn()

Parameters
[in]pix1 bpp
[in]orderof moment, either 1 or 2
Returns
na of first moment of fg pixels, by column, or NULL on error

Definition at line 2228 of file pix3.c.

◆ pixInvert()

PIX* pixInvert ( PIX pixd,
PIX pixs 
)

pixInvert()

Parameters
[in]pixd[optional]; this can be null, equal to pixs, or different from pixs
[in]pixs
Returns
pixd, or NULL on error
Notes:
     (1) This inverts pixs, for all pixel depths.
     (2) There are 3 cases:
          (a) pixd == null,   ~src --> new pixd
          (b) pixd == pixs,   ~src --> src  (in-place)
          (c) pixd != pixs,   ~src --> input pixd
     (3) For clarity, if the case is known, use these patterns:
          (a) pixd = pixInvert(NULL, pixs);
          (b) pixInvert(pixs, pixs);
          (c) pixInvert(pixd, pixs);

Definition at line 1481 of file pix3.c.

References pixCopy(), and pixRasterop().

Referenced by ccbaDisplayImage1(), ccbaDisplayImage2(), findNextUnvisited(), pixAutoPhotoinvert(), pixBlockrank(), pixDecideIfTable(), pixThresholdForFgBg(), and recogAverageSamples().

◆ pixMakeAlphaFromMask()

PIX* pixMakeAlphaFromMask ( PIX pixs,
l_int32  dist,
BOX **  pbox 
)

pixMakeAlphaFromMask()

Parameters
[in]pixs1 bpp
[in]distblending distance; typically 10 - 30
[out]pbox[optional] use NULL to get the full size
Returns
pixd (8 bpp gray, or NULL on error
Notes:
     (1) This generates a 8 bpp alpha layer that is opaque (256)
         over the FG of pixs, and goes transparent linearly away
         from the FG pixels, decaying to 0 (transparent) is an
         8-connected distance given by dist.  If dist == 0,
         this does a simple conversion from 1 to 8 bpp.
     (2) If &box == NULL, this returns an alpha mask that is the
         full size of pixs.  Otherwise, the returned mask pixd covers
         just the FG pixels of pixs, expanded by dist in each
         direction (if possible), and the returned box gives the
         location of the returned mask relative to pixs.
     (3) This is useful for painting through a mask and allowing
         blending of the painted image with an underlying image
         in the mask background for pixels near foreground mask pixels.
         For example, with an underlying rgb image pix1, an overlaying
         image rgb pix2, binary mask pixm, and dist > 0, this
         blending is achieved with:
             pix3 = pixMakeAlphaFromMask(pixm, dist, &box);
             boxGetGeometry(box, &x, &y, NULL, NULL);
             pix4 = pixBlendWithGrayMask(pix1, pix2, pix3, x, y);

Definition at line 1262 of file pix3.c.

◆ pixMakeArbMaskFromRGB()

PIX* pixMakeArbMaskFromRGB ( PIX pixs,
l_float32  rc,
l_float32  gc,
l_float32  bc,
l_float32  thresh 
)

pixMakeArbMaskFromRGB()

Parameters
[in]pixs32 bpp RGB
[in]rc,gc,bcarithmetic factors; can be negative
[in]threshlower threshold on weighted sum of components
Returns
pixd 1 bpp mask, or NULL on error
Notes:
     (1) This generates a 1 bpp mask image, where a 1 is written in
         the mask for each pixel in pixs that satisfies
              rc * rval + gc * gval + bc * bval > thresh
         where rval is the red component, etc.
     (2) Unlike with pixConvertToGray(), there are no constraints
         on the color coefficients, which can be negative.  For
         example, a mask that discriminates against red and in favor
         of blue will have rc < 0.0 and bc > 0.0.
     (3) To make the result independent of intensity (the 'V' in HSV),
         select coefficients so that thresh = 0.  Then the result
         is not changed when all components are multiplied by the
         same constant (as long as nothing saturates).  This can be
         useful if, for example, the illumination is not uniform.

Definition at line 1113 of file pix3.c.

◆ pixMakeMaskFromLUT()

PIX* pixMakeMaskFromLUT ( PIX pixs,
l_int32 *  tab 
)

pixMakeMaskFromLUT()

Parameters
[in]pixs2, 4 or 8 bpp; can be colormapped
[in]tab256-entry LUT; 1 means to write to mask
Returns
pixd 1 bpp mask, or NULL on error
Notes:
     (1) This generates a 1 bpp mask image, where a 1 is written in
         the mask for each pixel in pixs that has a value corresponding
         to a 1 in the LUT.
     (2) The LUT should be of size 256.

Definition at line 1046 of file pix3.c.

References pixCreate(), and pixGetDimensions().

◆ pixMakeMaskFromVal()

PIX* pixMakeMaskFromVal ( PIX pixs,
l_int32  val 
)

pixMakeMaskFromVal()

Parameters
[in]pixs2, 4 or 8 bpp; can be colormapped
[in]valpixel value
Returns
pixd 1 bpp mask, or NULL on error
Notes:
     (1) This generates a 1 bpp mask image, where a 1 is written in
         the mask for each pixel in pixs that has a value val.
     (2) If no pixels have the value, an empty mask is generated.

Definition at line 991 of file pix3.c.

References pixCreate(), and pixGetDimensions().

◆ pixMirroredTiling()

PIX* pixMirroredTiling ( PIX pixs,
l_int32  w,
l_int32  h 
)

pixMirroredTiling()

Parameters
[in]pixs8 or 32 bpp, small tile; to be replicated
[in]w,hdimensions of output pix
Returns
pixd usually larger pix, mirror-tiled with pixs, or NULL on error
Notes:
     (1) This uses mirrored tiling, where each row alternates
         with LR flips and every column alternates with TB
         flips, such that the result is a tiling with identical
         2 x 2 tiles, each of which is composed of these transforms:
                 -----------------
                 | 1    |  LR    |
                 -----------------
                 | TB   |  LR/TB |
                 -----------------

Definition at line 3355 of file pix3.c.

References PIX_SRC, pixCopySpp(), pixCreate(), pixDestroy(), pixFlipLR(), pixFlipTB(), pixGetDimensions(), and pixRasterop().

◆ pixOr()

PIX* pixOr ( PIX pixd,
PIX pixs1,
PIX pixs2 
)

pixOr()

Parameters
[in]pixd[optional]; this can be null, equal to pixs1, different from pixs1
[in]pixs1can be == pixd
[in]pixs2must be != pixd
Returns
pixd always
Notes:
     (1) This gives the union of two images with equal depth,
         aligning them to the the UL corner.  pixs1 and pixs2
         need not have the same width and height.
     (2) There are 3 cases:
           (a) pixd == null,   (src1 | src2) --> new pixd
           (b) pixd == pixs1,  (src1 | src2) --> src1  (in-place)
           (c) pixd != pixs1,  (src1 | src2) --> input pixd
     (3) For clarity, if the case is known, use these patterns:
           (a) pixd = pixOr(NULL, pixs1, pixs2);
           (b) pixOr(pixs1, pixs1, pixs2);
           (c) pixOr(pixd, pixs1, pixs2);
     (4) The size of the result is determined by pixs1.
     (5) The depths of pixs1 and pixs2 must be equal.
     (6) Note carefully that the order of pixs1 and pixs2 only matters
         for the in-place case.  For in-place, you must have
         pixd == pixs1.  Setting pixd == pixs2 gives an incorrect
         result: the copy puts pixs1 image data in pixs2, and
         the rasterop is then between pixs2 and pixs2 (a no-op).

Definition at line 1530 of file pix3.c.

Referenced by pixDecideIfTable().

◆ pixPaintSelfThroughMask()

l_ok pixPaintSelfThroughMask ( PIX pixd,
PIX pixm,
l_int32  x,
l_int32  y,
l_int32  searchdir,
l_int32  mindist,
l_int32  tilesize,
l_int32  ntiles,
l_int32  distblend 
)

pixPaintSelfThroughMask()

Parameters
[in]pixd8 bpp gray or 32 bpp rgb; not colormapped
[in]pixm1 bpp mask
[in]x,yorigin of pixm relative to pixd; must not be negative
[in]searchdirL_HORIZ, L_VERT or L_BOTH_DIRECTIONS
[in]mindistmin distance of nearest tile edge to box; >= 0
[in]tilesizerequested size for tiling; may be reduced
[in]ntilesnumber of tiles tested in each row/column
[in]distblenddistance outside the fg used for blending with pixs
Returns
0 if OK; 1 on error
Notes:
     (1) In-place operation; pixd is changed.
     (2) If pixm == NULL, it's a no-op.
     (3) The mask origin is placed at (x,y) on pixd, and the
         operation is clipped to the intersection of pixd and the
         fg of the mask.
     (4) tsize is the the requested size for tiling.  The actual
         actual size for each c.c. will be bounded by the minimum
         dimension of the c.c.
     (5) For mindist, searchdir and ntiles, see pixFindRepCloseTile().
         They determine the set of possible tiles that can be used
         to build a larger mirrored tile to paint onto pixd through
         the c.c. of pixm.
     (6) distblend is used for alpha blending.  It is only applied
         if there is exactly one c.c. in the mask.  Use distblend == 0
         to skip blending and just paint through the 1 bpp mask.
     (7) To apply blending to more than 1 component, call this function
         repeatedly with pixm, x and y representing one component of
         the mask each time.  This would be done as follows, for an
         underlying image pixs and mask pixm of components to fill:
             Boxa *boxa = pixConnComp(pixm, &pixa, 8);
             n = boxaGetCount(boxa);
             for (i = 0; i < n; i++) {
                 Pix *pix = pixaGetPix(pixa, i, L_CLONE);
                 Box *box = pixaGetBox(pixa, i, L_CLONE);
                 boxGetGeometry(box, &bx, &by, &bw, &bh);
                 pixPaintSelfThroughMask(pixs, pix, bx, by, searchdir,
                                    mindist, tilesize, ntiles, distblend);
                 pixDestroy(&pix);
                 boxDestroy(&box);
             }
             pixaDestroy(&pixa);
             boxaDestroy(&boxa);
     (8) If no tiles can be found, this falls back to estimating the
         color near the boundary of the region to be textured.
     (9) This can be used to replace the pixels in some regions of
         an image by selected neighboring pixels.  The mask represents
         the pixels to be replaced.  For each connected component in
         the mask, this function selects up to two tiles of neighboring
         pixels to be used for replacement of pixels represented by
         the component (i.e., under the FG of that component in the mask).
         After selection, mirror replication is used to generate an
         image that is large enough to cover the component.  Alpha
         blending can also be used outside of the component, but near the
         edge, to blur the transition between painted and original pixels.

Definition at line 836 of file pix3.c.

◆ pixPaintThroughMask()

l_ok pixPaintThroughMask ( PIX pixd,
PIX pixm,
l_int32  x,
l_int32  y,
l_uint32  val 
)

pixPaintThroughMask()

Parameters
[in]pixd1, 2, 4, 8, 16 or 32 bpp; or colormapped
[in]pixm[optional] 1 bpp mask
[in]x,yorigin of pixm relative to pixd; can be negative
[in]valpixel value to set at each masked pixel
Returns
0 if OK; 1 on error
Notes:
     (1) In-place operation.  Calls pixSetMaskedCmap() for colormapped
         images.
     (2) For 1, 2, 4, 8 and 16 bpp gray, we take the appropriate
         number of least significant bits of val.
     (3) If pixm == NULL, it's a no-op.
     (4) The mask origin is placed at (x,y) on pixd, and the
         operation is clipped to the intersection of rectangles.
     (5) For rgb, the components in val are in the canonical locations,
         with red in location COLOR_RED, etc.
     (6) Implementation detail 1:
         For painting with val == 0 or val == maxval, you can use rasterop.
         If val == 0, invert the mask so that it's 0 over the region
         into which you want to write, and use PIX_SRC & PIX_DST to
         clear those pixels.  To write with val = maxval (all 1's),
         use PIX_SRC | PIX_DST to set all bits under the mask.
     (7) Implementation detail 2:
         The rasterop trick can be used for depth > 1 as well.
         For val == 0, generate the mask for depth d from the binary
         mask using
             pixmd = pixUnpackBinary(pixm, d, 1);
         and use pixRasterop() with PIX_MASK.  For val == maxval,
             pixmd = pixUnpackBinary(pixm, d, 0);
         and use pixRasterop() with PIX_PAINT.
         But note that if d == 32 bpp, it is about 3x faster to use
         the general implementation (not pixRasterop()).
     (8) Implementation detail 3:
         It might be expected that the switch in the inner loop will
         cause large branching delays and should be avoided.
         This is not the case, because the entrance is always the
         same and the compiler can correctly predict the jump.

Definition at line 618 of file pix3.c.

Referenced by boxaCompareRegions(), evalColorfillData(), kernelDisplayInPix(), pixDisplayDiffBinary(), recogShowPath(), selaAddCrossJunctions(), selaAddTJunctions(), and wshedRenderFill().

◆ pixSetMasked()

l_ok pixSetMasked ( PIX pixd,
PIX pixm,
l_uint32  val 
)

pixSetMasked()

Parameters
[in]pixd1, 2, 4, 8, 16 or 32 bpp; or colormapped
[in]pixm[optional] 1 bpp mask; no operation if NULL
[in]valvalue to set at each masked pixel
Returns
0 if OK; 1 on error
Notes:
     (1) In-place operation.
     (2) NOTE: For cmapped images, this calls pixSetMaskedCmap().
         val must be the 32-bit color representation of the RGB pixel.
         It is not the index into the colormap!
     (2) If pixm == NULL, a warning is given.
     (3) This is an implicitly aligned operation, where the UL
         corners of pixd and pixm coincide.  A warning is
         issued if the two image sizes differ significantly,
         but the operation proceeds.
     (4) Each pixel in pixd that co-locates with an ON pixel
         in pixm is set to the specified input value.
         Other pixels in pixd are not changed.
     (5) You can visualize this as painting the color through
         the mask, as a stencil.
     (6) If you do not want to have the UL corners aligned,
         use the function pixSetMaskedGeneral(), which requires
         you to input the UL corner of pixm relative to pixd.
     (7) Implementation details: see comments in pixPaintThroughMask()
         for when we use rasterop to do the painting.

Definition at line 163 of file pix3.c.

◆ pixSetMaskedGeneral()

l_ok pixSetMaskedGeneral ( PIX pixd,
PIX pixm,
l_uint32  val,
l_int32  x,
l_int32  y 
)

pixSetMaskedGeneral()

Parameters
[in]pixd8, 16 or 32 bpp
[in]pixm[optional] 1 bpp mask; no operation if null
[in]valvalue to set at each masked pixel
[in]x,ylocation of UL corner of pixm relative to pixd; can be negative
Returns
0 if OK; 1 on error
Notes:
     (1) This is an in-place operation.
     (2) Alignment is explicit.  If you want the UL corners of
         the two images to be aligned, use pixSetMasked().
     (3) A typical use would be painting through the foreground
         of a small binary mask pixm, located somewhere on a
         larger pixd.  Other pixels in pixd are not changed.
     (4) You can visualize this as painting the color through
         the mask, as a stencil.
     (5) This uses rasterop to handle clipping and different depths of pixd.
     (6) If pixd has a colormap, you should call pixPaintThroughMask().
     (7) Why is this function here, if pixPaintThroughMask() does the
         same thing, and does it more generally?  I've retained it here
         to show how one can paint through a mask using only full
         image rasterops, rather than pixel peeking in pixm and poking
         in pixd.  It's somewhat baroque, but I found it amusing.

Definition at line 300 of file pix3.c.

Referenced by kernelDisplayInPix().

◆ pixSetUnderTransparency()

PIX* pixSetUnderTransparency ( PIX pixs,
l_uint32  val,
l_int32  debug 
)

pixSetUnderTransparency()

Parameters
[in]pixs32 bpp rgba
[in]val32 bit unsigned color to use where alpha == 0
[in]debugdisplays layers of pixs
Returns
pixd 32 bpp rgba, or NULL on error
Notes:
     (1) This sets the r, g and b components under every fully
         transparent alpha component to val.  The alpha components
         are unchanged.
     (2) Full transparency is denoted by alpha == 0.  Setting
         all pixels to a constant val where alpha is transparent
         can improve compressibility by reducing the entropy.
     (3) The visual result depends on how the image is displayed.
         (a) For display devices that respect the use of the alpha
             layer, this will not affect the appearance.
         (b) For typical leptonica operations, alpha is ignored,
             so there will be a change in appearance because this
             resets the rgb values in the fully transparent region.
     (4) pixRead() and pixWrite() will, by default, read and write
         4-component (rgba) pix in png format.  To ignore the alpha
         component after reading, or omit it on writing, pixSetSpp(..., 3).
     (5) Here are some examples:
         * To convert all fully transparent pixels in a 4 component
           (rgba) png file to white:
             pixs = pixRead(<infile>);
             pixd = pixSetUnderTransparency(pixs, 0xffffff00, 0);
         * To write pixd with the alpha component:
             pixWrite(<outfile>, pixd, IFF_PNG);
         * To write and rgba image without the alpha component, first do:
             pixSetSpp(pixd, 3);
           If you later want to use the alpha, spp must be reset to 4.
         * (fancier) To remove the alpha by blending the image over
           a white background:
             pixRemoveAlpha()
           This changes all pixel values where the alpha component is
           not opaque (255).
     (6) Caution.  rgb images in leptonica typically have value 0 in
         the alpha channel, which is fully transparent.  If spp for
         such an image were changed from 3 to 4, the image becomes
         fully transparent, and this function will set each pixel to val.
         If you really want to set every pixel to the same value,
         use pixSetAllArbitrary().
     (7) This is useful for compressing an RGBA image where the part
         of the image that is fully transparent is random junk; compression
         is typically improved by setting that region to a constant.
         For rendering as a 3 component RGB image over a uniform
         background of arbitrary color, use pixAlphaBlendUniform().

Definition at line 1188 of file pix3.c.

◆ pixSubtract()

PIX* pixSubtract ( PIX pixd,
PIX pixs1,
PIX pixs2 
)

pixSubtract()

Parameters
[in]pixd[optional]; this can be null, equal to pixs1, equal to pixs2, or different from both pixs1 and pixs2
[in]pixs1can be == pixd
[in]pixs2can be == pixd
Returns
pixd always
Notes:
     (1) This gives the set subtraction of two images with equal depth,
         aligning them to the the UL corner.  pixs1 and pixs2
         need not have the same width and height.
     (2) Source pixs2 is always subtracted from source pixs1.
         The result is
                 pixs1 \ pixs2 = pixs1 & (~pixs2)
     (3) There are 4 cases:
           (a) pixd == null,   (src1 - src2) --> new pixd
           (b) pixd == pixs1,  (src1 - src2) --> src1  (in-place)
           (c) pixd == pixs2,  (src1 - src2) --> src2  (in-place)
           (d) pixd != pixs1 && pixd != pixs2),
                                (src1 - src2) --> input pixd
     (4) For clarity, if the case is known, use these patterns:
           (a) pixd = pixSubtract(NULL, pixs1, pixs2);
           (b) pixSubtract(pixs1, pixs1, pixs2);
           (c) pixSubtract(pixs2, pixs1, pixs2);
           (d) pixSubtract(pixd, pixs1, pixs2);
     (5) The size of the result is determined by pixs1.
     (6) The depths of pixs1 and pixs2 must be equal.

Definition at line 1717 of file pix3.c.

Referenced by pixDecideIfTable(), pixDisplayDiffBinary(), and selDisplayInPix().

◆ pixThresholdPixelSum()

l_ok pixThresholdPixelSum ( PIX pix,
l_int32  thresh,
l_int32 *  pabove,
l_int32 *  tab8 
)

pixThresholdPixelSum()

Parameters
[in]pix1 bpp
[in]threshthreshold
[out]pabove1 if above threshold; 0 if equal to or less than threshold
[in]tab8[optional] 8-bit pixel lookup table
Returns
0 if OK; 1 on error
Notes:
     (1) This sums the ON pixels and returns immediately if the count
         goes above threshold.  It is therefore more efficient
         for matching images (by running this function on the xor of
         the 2 images) than using pixCountPixels(), which counts all
         pixels before returning.

Definition at line 2284 of file pix3.c.

◆ pixVarianceByColumn()

NUMA* pixVarianceByColumn ( PIX pix,
BOX box 
)

pixVarianceByColumn()

Parameters
[in]pix8 or 16 bpp; no colormap
[in]box[optional] clipping box for variance; can be null
Returns
na of rmsdev by column, or NULL on error
Notes:
     (1) To resample for a bin size different from 1, use
         numaUniformSampling() on the result of this function.
     (2) We are actually computing the RMS deviation in each row.
         This is the square root of the variance.

Definition at line 2852 of file pix3.c.

References pixGetDimensions().

◆ pixVarianceByRow()

NUMA* pixVarianceByRow ( PIX pix,
BOX box 
)

pixVarianceByRow()

Parameters
[in]pix8 or 16 bpp; no colormap
[in]box[optional] clipping box for variance; can be null
Returns
na of rmsdev by row, or NULL on error
Notes:
     (1) To resample for a bin size different from 1, use
         numaUniformSampling() on the result of this function.
     (2) We are actually computing the RMS deviation in each row.
         This is the square root of the variance.

Definition at line 2789 of file pix3.c.

References pixGetDimensions().

◆ pixVarianceInRect()

l_ok pixVarianceInRect ( PIX pix,
BOX box,
l_float32 *  prootvar 
)

pixVarianceInRect()

Parameters
[in]pix1, 2, 4, 8 bpp; not cmapped
[in]box[optional] if null, use entire image
[out]prootvarsqrt variance of pixel values in region
Returns
0 if OK; 1 on error

Definition at line 2908 of file pix3.c.

References pixGetDimensions().

◆ pixXor()

PIX* pixXor ( PIX pixd,
PIX pixs1,
PIX pixs2 
)

pixXor()

Parameters
[in]pixd[optional]; this can be null, equal to pixs1, different from pixs1
[in]pixs1can be == pixd
[in]pixs2must be != pixd
Returns
pixd always
Notes:
     (1) This gives the XOR of two images with equal depth,
         aligning them to the the UL corner.  pixs1 and pixs2
         need not have the same width and height.
     (2) There are 3 cases:
           (a) pixd == null,   (src1 ^ src2) --> new pixd
           (b) pixd == pixs1,  (src1 ^ src2) --> src1  (in-place)
           (c) pixd != pixs1,  (src1 ^ src2) --> input pixd
     (3) For clarity, if the case is known, use these patterns:
           (a) pixd = pixXor(NULL, pixs1, pixs2);
           (b) pixXor(pixs1, pixs1, pixs2);
           (c) pixXor(pixd, pixs1, pixs2);
     (4) The size of the result is determined by pixs1.
     (5) The depths of pixs1 and pixs2 must be equal.
     (6) Note carefully that the order of pixs1 and pixs2 only matters
         for the in-place case.  For in-place, you must have
         pixd == pixs1.  Setting pixd == pixs2 gives an incorrect
         result: the copy puts pixs1 image data in pixs2, and
         the rasterop is then between pixs2 and pixs2 (a no-op).

Definition at line 1654 of file pix3.c.

Referenced by boxaCompareRegions(), pixExtractBoundary(), and recogShowPath().

◆ pixZero()

l_ok pixZero ( PIX pix,
l_int32 *  pempty 
)

pixZero()

Parameters
[in]pixall depths; colormap OK
[out]pempty1 if all bits in image data field are 0; 0 otherwise
Returns
0 if OK; 1 on error
Notes:
     (1) For a binary image, if there are no fg (black) pixels, empty = 1.
     (2) For a grayscale image, if all pixels are black (0), empty = 1.
     (3) For an RGB image, if all 4 components in every pixel is 0,
         empty = 1.
     (4) For a colormapped image, pixel values are 0.  The colormap
         is ignored.

Definition at line 1777 of file pix3.c.

Referenced by pixAutoPhotoinvert(), pixDecideIfTable(), pixDecideIfText(), pixSelectByArea(), pixSelectByAreaFraction(), pixSelectByPerimSizeRatio(), pixSelectByPerimToAreaRatio(), pixSelectBySize(), pixSelectByWidthHeightRatio(), and recogModifyTemplate().