#include "allheaders.h"
Go to the source code of this file.
|
static COLOREL * | colorelCreate (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_COLORFILL * | l_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) |
|
PIX * | pixColorFill (PIX *pixs, l_int32 minmax, l_int32 maxdiff, l_int32 smooth, l_int32 minarea, l_int32 debug) |
|
PIXA * | makeColorfillTestData (l_int32 w, l_int32 h, l_int32 nseeds, l_int32 range) |
|
|
static l_int32 | DefaultMinMax = 70 |
|
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.
◆ colorsAreSimilarForFill()
static l_int32 colorsAreSimilarForFill |
( |
l_uint32 |
val1, |
|
|
l_uint32 |
val2, |
|
|
l_int32 |
maxdiff |
|
) |
| |
|
static |
colorsAreSimilarForFill()
- Parameters
-
[in] | val1 | color of pixel 1, as 0xrrggbb00 |
[in] | val2 | color of pixel 2, as 0xrrggbb00 |
[in] | maxdiff | max 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()
static l_int32 evalColorfillData |
( |
L_COLORFILL * |
cf, |
|
|
l_int32 |
debug |
|
) |
| |
|
static |
evalColorfillData()
- Parameters
-
[in] | cf | colorfill with masks generated for all tiles |
[in] | debug | show segmented regions with their median color |
- Returns
- 0 if OK, 1 on error
Definition at line 842 of file colorfill.c.
References boxaDestroy(), boxDestroy(), boxGetGeometry(), composeRGBPixel(), L_Colorfill::dnaa, L_CLONE, L_COPY, l_dnaaAddDna(), l_dnaAddNumber(), l_dnaCreate(), L_INSERT, lept_stderr(), makePixelSumTab8(), L_Colorfill::naa, numaaAddNuma(), numaAddNumber(), numaaGetNuma(), numaCreate(), numaDestroy(), numaWriteStderr(), L_Colorfill::nx, L_Colorfill::ny, pixaAddPix(), L_Colorfill::pixadb, pixaDestroy(), pixaGetBox(), pixaGetCount(), pixaGetPix(), L_Colorfill::pixam, L_Colorfill::pixas, pixConnComp(), pixCountPixels(), pixCreate(), pixDestroy(), pixGetDimensions(), pixGetRankValueMaskedRGB(), and pixPaintThroughMask().
◆ findNextUnvisited()
static l_int32 findNextUnvisited |
( |
PIX * |
pixv, |
|
|
l_int32 * |
px, |
|
|
l_int32 * |
py |
|
) |
| |
|
static |
◆ l_colorfillCreate()
l_colorfillCreate()
- Parameters
-
[in] | pixs | input RGB image |
[in] | nx | requested number of tiles in each row |
[in] | ny | requested 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()
l_colorfillDestroy()
- Parameters
-
[in,out] | pcf | will be set to null before returning |
- Returns
- void
Definition at line 156 of file colorfill.c.
References boxaDestroy(), L_Colorfill::boxas, L_Colorfill::dnaa, l_dnaaDestroy(), L_Colorfill::naa, numaaDestroy(), L_Colorfill::pixadb, pixaDestroy(), L_Colorfill::pixam, L_Colorfill::pixas, pixDestroy(), L_Colorfill::pixs, and L_Colorfill::pixst.
◆ makeColorfillTestData()
PIXA* makeColorfillTestData |
( |
l_int32 |
w, |
|
|
l_int32 |
h, |
|
|
l_int32 |
nseeds, |
|
|
l_int32 |
range |
|
) |
| |
makeColorfillTestData()
- Parameters
-
[in] | w | width of generated pix |
[in] | h | height of generated pix |
[in] | nseeds | number of regions |
[in] | range | of 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] | cf | colorfill |
[in] | rref | reference value for red component |
[in] | gref | reference value for green component |
[in] | bref | reference value for blue component |
[in] | minmax | min of max component for possible color region |
[in] | maxdiff | max component diff to be in same color region |
[in] | minarea | min number of pixels for a color region |
[in] | smooth | low-pass kernel size (1,3,5); use 1 to skip |
[in] | debug | generates 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] | pixs | 32 bpp RGB |
[in] | minmax | min of max component for possible color region |
[in] | maxdiff | max component diff to be in same color region |
[in] | smooth | low-pass kernel size (1,3,5); use 1 to skip |
[in] | minarea | min number of pixels for a color region |
[in] | debug | generates 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] | pixs | 32 bpp rgb |
[in] | pixv | 1 bpp labeling visited pixels |
[out] | ppta | points visited with similar colors during fill |
[in] | x | starting x coord for fill (seed) |
[in] | y | starting y coord for fill (seed) |
[in] | lq | head of queue holding pixels |
[in] | maxdiff | max component diff allowed for similar pixels |
[in] | minarea | min size of component to keep |
[in] | debug | output 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 |
◆ pixelIsOnColorBoundary()
static l_int32 pixelIsOnColorBoundary |
( |
PIX * |
pixs, |
|
|
l_int32 |
x, |
|
|
l_int32 |
y |
|
) |
| |
|
static |
◆ pixGetVisitedNeighbors()
static void pixGetVisitedNeighbors |
( |
PIX * |
pixs, |
|
|
l_int32 |
x, |
|
|
l_int32 |
y, |
|
|
l_uint32 * |
visited |
|
) |
| |
|
static |
pixGetVisitedNeighbors()
- Parameters
-
[in] | pixs | 1 bpp, representing visited locations |
[in] | x | x coord of pixel |
[in] | y | y coord of pixel |
[in,out] | visited | array 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().