Leptonica  1.83.1
Image processing and image analysis suite
colorfill.c File Reference
#include "allheaders.h"

Go to the source code of this file.

Data Structures

struct  ColorEl
 

Typedefs

typedef struct ColorEl COLOREL
 

Functions

static COLORELcolorelCreate (l_int32 x, l_int32 y, l_uint32 color)
 
static void pixColorFillFromSeed (PIX *pixs, PIX *pixv, PTA **ppta, l_int32 x, l_int32 y, L_QUEUE *lq, l_int32 maxdiff, l_int32 minarea, l_int32 debug)
 
static void pixGetVisitedNeighbors (PIX *pixs, l_int32 x, l_int32 y, l_uint32 *visited)
 
static l_int32 findNextUnvisited (PIX *pixv, l_int32 *px, l_int32 *py)
 
static l_int32 colorsAreSimilarForFill (l_uint32 val1, l_uint32 val2, l_int32 maxdiff)
 
static l_int32 pixelColorIsValid (l_uint32 val, l_int32 minmax)
 
static l_int32 pixelIsOnColorBoundary (PIX *pixs, l_int32 x, l_int32 y)
 
static l_int32 evalColorfillData (L_COLORFILL *cf, l_int32 debug)
 
L_COLORFILLl_colorfillCreate (PIX *pixs, l_int32 nx, l_int32 ny)
 
void l_colorfillDestroy (L_COLORFILL **pcf)
 
l_ok pixColorContentByLocation (L_COLORFILL *cf, l_int32 rref, l_int32 gref, l_int32 bref, l_int32 minmax, l_int32 maxdiff, l_int32 minarea, l_int32 smooth, l_int32 debug)
 
PIXpixColorFill (PIX *pixs, l_int32 minmax, l_int32 maxdiff, l_int32 smooth, l_int32 minarea, l_int32 debug)
 
PIXAmakeColorfillTestData (l_int32 w, l_int32 h, l_int32 nseeds, l_int32 range)
 

Variables

static l_int32 DefaultMinMax = 70
 

Detailed Description


     Determine color content using proximity.  What can we say about the
     color in an image from growing regions with nearly the same color?

        L_COLORFILL  *l_colorfillCreate()
        void          l_colorfillDestroy()

        L_COLORFILL  *pixColorContentByLocation()
        PIX          *pixColorFill()

     Generate data for testing
        PIXA         *makeColorfillTestData()

     Static helpers
        static COLOREL      *colorelCreate()
        static void          pixColorFillFromSeed()
        static void          pixGetVisitedNeighbors()
        static l_int32       findNextUnvisited()
        static l_int32       colorsAreSimilarForFill()
        static void          pixelColorIsValid()
        static l_int32       pixelIsOnColorBoundary()
        static l_int32       evalColorfillData()

 See colorcontent.c for location-independent measures of the amount
 of color in an image.

Definition in file colorfill.c.

Function Documentation

◆ colorsAreSimilarForFill()

static l_int32 colorsAreSimilarForFill ( l_uint32  val1,
l_uint32  val2,
l_int32  maxdiff 
)
static

colorsAreSimilarForFill()

Parameters
[in]val1color of pixel 1, as 0xrrggbb00
[in]val2color of pixel 2, as 0xrrggbb00
[in]maxdiffmax of difference function to be similar
Returns
1 if val1 and val2 are similar; 0 otherwise
Notes:
     (1) An example will explain the approach.  Suppose we have:
           val1 = {100, 130, 70}
           val2 = {90, 135, 62}
         First find that red is the color with largest abs(difference):
           rdiff = val1 - val2 = 10
         Find the green and blue differences
           gdiff = 130 - 135 = -5
           bdiff = 70 - 62 = 8
         and subtract each from rdiff:
           rdiff - gdiff = 15
           rdiff - bdiff = 7
         The max of these is 15, which is then compared with maxdiff

Definition at line 750 of file colorfill.c.

References extractRGBValues().

◆ evalColorfillData()

◆ findNextUnvisited()

static l_int32 findNextUnvisited ( PIX pixv,
l_int32 *  px,
l_int32 *  py 
)
static

findNextUnvisited()

Parameters
[in]pixvvisited pixels
[in,out]pyinput start scanline; output y-coord of next seed
[out]pxx-coord of next seed
Returns
1 if new seed point is found; 0 if there are none
Notes:
     (1) Start the search at the beginning of the raster line
         for the pixel that ended the previous search.

Definition at line 710 of file colorfill.c.

References nextOnPixelInRaster(), pixCopy(), pixDestroy(), and pixInvert().

◆ l_colorfillCreate()

L_COLORFILL* l_colorfillCreate ( PIX pixs,
l_int32  nx,
l_int32  ny 
)

l_colorfillCreate()

Parameters
[in]pixsinput RGB image
[in]nxrequested number of tiles in each row
[in]nyrequested number of tiles in each column
Returns
boxa, or NULL on error
Notes:
     (1) Tiles must at least 10 pixels in each dimension.

Definition at line 107 of file colorfill.c.

◆ l_colorfillDestroy()

void l_colorfillDestroy ( L_COLORFILL **  pcf)

◆ makeColorfillTestData()

PIXA* makeColorfillTestData ( l_int32  w,
l_int32  h,
l_int32  nseeds,
l_int32  range 
)

makeColorfillTestData()

Parameters
[in]wwidth of generated pix
[in]hheight of generated pix
[in]nseedsnumber of regions
[in]rangeof color component values
Returns
pixa various pix with filled regions of random color, or NULL on error
Notes:
     (1) The seeds are random points.  The colors are assigned
         randomly from a restricted range of component values,
         in [128 - range/2 ... 128 + range/2]
     (2) Output is pixa:
         * pixa[0] cmapped, with color regions shown
  • pixa[1] cmapped, additionally with boundary pixels set to black
  • pixa[2] cmapped, as in pixa[1] with all non-black pixels in the same color

Definition at line 404 of file colorfill.c.

References composeRGBPixel(), extractRGBValues(), genRandomIntOnInterval(), L_COPY, l_dnaAddNumber(), l_dnaCreate(), l_dnaDestroy(), l_dnaGetDValue(), L_INSERT, pixaAddPix(), pixaCreate(), pixcmapAddColor(), pixcmapCreate(), pixCopy(), pixCreate(), pixDestroy(), pixelIsOnColorBoundary(), pixSeedspread(), pixSetColormap(), pixSetPixel(), ptaAddPt(), ptaCreate(), ptaDestroy(), and ptaGetIPt().

◆ pixColorContentByLocation()

l_ok pixColorContentByLocation ( L_COLORFILL cf,
l_int32  rref,
l_int32  gref,
l_int32  bref,
l_int32  minmax,
l_int32  maxdiff,
l_int32  minarea,
l_int32  smooth,
l_int32  debug 
)

pixColorContentByLocation()

Parameters
[in]cfcolorfill
[in]rrefreference value for red component
[in]grefreference value for green component
[in]brefreference value for blue component
[in]minmaxmin of max component for possible color region
[in]maxdiffmax component diff to be in same color region
[in]minareamin number of pixels for a color region
[in]smoothlow-pass kernel size (1,3,5); use 1 to skip
[in]debuggenerates debug images and fill info
Returns
0 if OK, 1 on error
Notes:
     (1) This computes color fill information in each tile, identifying
         regions of approximately constant color.  It does this
         independently for each tile, using flood fills.  Regions
         of low intensity are considered 'not colorful'.
     (2) The three numbers (rref, gref and bref) can be thought
         of in two ways:
           (a) as rgb values in the image corresponding to white,
               to compensate for an unbalanced color white point.
           (b) as the median or mean values of the background color
               of a scan.
         The gamma TRC transformation, which does not change hue, is used
         to modify all colors so that these reference values become white.
         These three numbers must either be all 0 or all non-zero.
         To skip the TRC transform, set them all to 0.
     (3) If the maximum component after white point correction,
         max(r,g,b), is less than minmax, the pixel color is invalid, and it
         is assigned its neighbor's value in the filling operation.
         Use minmax = 0 for a default value.

Definition at line 222 of file colorfill.c.

◆ pixColorFill()

PIX* pixColorFill ( PIX pixs,
l_int32  minmax,
l_int32  maxdiff,
l_int32  smooth,
l_int32  minarea,
l_int32  debug 
)

pixColorFill()

Parameters
[in]pixs32 bpp RGB
[in]minmaxmin of max component for possible color region
[in]maxdiffmax component diff to be in same color region
[in]smoothlow-pass kernel size (1,3,5); use 1 to skip
[in]minareamin number of pixels for a color region
[in]debuggenerates debug images and fill info
Returns
pixm mask showing connected regions of similar color, or null on error
Notes:
     (1) This is the basic color filling operation.  It sets the
         non-color pixel to black, optionally does a low-pass filter,
         and grows the 8-connected color components.  Finally, it
         removes components that have a small area.

Definition at line 293 of file colorfill.c.

◆ pixColorFillFromSeed()

static void pixColorFillFromSeed ( PIX pixs,
PIX pixv,
PTA **  ppta,
l_int32  x,
l_int32  y,
L_QUEUE lq,
l_int32  maxdiff,
l_int32  minarea,
l_int32  debug 
)
static

pixColorFillFromSeed()

Parameters
[in]pixs32 bpp rgb
[in]pixv1 bpp labeling visited pixels
[out]pptapoints visited with similar colors during fill
[in]xstarting x coord for fill (seed)
[in]ystarting y coord for fill (seed)
[in]lqhead of queue holding pixels
[in]maxdiffmax component diff allowed for similar pixels
[in]minareamin size of component to keep
[in]debugoutput some text data
Returns
void
Notes:
     (1) Use 8-connected filling.  It is faster because it reduces the
         number of single-pixel noise components near color boundaries.
     (2) The seed pixel at (x,y) is unvisited, and can never be on the
         exterior boundary of the tile pixs.
     (3) If the size of the connected component >= minarea, we return
         the array of pixel locations; otherwise, return NULL for the pta.

Definition at line 529 of file colorfill.c.

References pixGetPixel().

◆ pixelColorIsValid()

static l_int32 pixelColorIsValid ( l_uint32  val,
l_int32  minmax 
)
static

pixelColorIsValid()

Parameters
[in]valcolor, as 0xrrggbb00
[in]minmaxmax component must be < minmax to be valid
Returns
0 if max component < minmax; 1 otherwise

Definition at line 783 of file colorfill.c.

References extractRGBValues().

◆ pixelIsOnColorBoundary()

static l_int32 pixelIsOnColorBoundary ( PIX pixs,
l_int32  x,
l_int32  y 
)
static

pixelIsOnColorBoundary()

Parameters
[in]pixs32 bpp rgb or 8 bpp with colormap
[in]x,ylocation of pixel of interest
Returns
1 if at least one neighboring pixel had a different color; 0 otherwise.

Definition at line 805 of file colorfill.c.

References pixGetDimensions(), and pixGetPixel().

Referenced by makeColorfillTestData().

◆ pixGetVisitedNeighbors()

static void pixGetVisitedNeighbors ( PIX pixs,
l_int32  x,
l_int32  y,
l_uint32 *  visited 
)
static

pixGetVisitedNeighbors()

Parameters
[in]pixs1 bpp, representing visited locations
[in]xx coord of pixel
[in]yy coord of pixel
[in,out]visitedarray of 8 int
Returns
void
Notes:
     (1) The values of the neighbors of (x,y) in pixs, given in
         order {W,N,E,S,NW,NE,SW,SE}, are returned in visited.
         A "1" value means that pixel has been visited.  Initialize
         each neighbor to 1 (visited).
     (2) The input point (x,y) is never on the outer boundary of pixs,
         (e.g., x >= 1, y >= 1), so no checking is required.

Definition at line 679 of file colorfill.c.

References pixGetPixel().