71 #include <config_auto.h>
74 #include "allheaders.h"
78 static const l_int32 DefaultDistanceToBoundary = 1;
79 static const l_int32 MaxDistanceToBoundary = 4;
83 static const l_int32 DefaultMinRunlength = 3;
87 static const l_int32 DefaultSelScalefactor = 7;
88 static const l_int32 MaxSelScalefactor = 31;
91 #define DEBUG_DISPLAY_HM_SEL 0
159 l_int32 ws, hs, w, h, x, y, xval, yval, i, j, nh, nm;
160 l_float32 delh, delw;
162 PIX *pixt1, *pixt2, *pixfg, *pixbg;
166 if (ppixe) *ppixe = NULL;
168 return (
SEL *)ERROR_PTR(
"pixs not defined", __func__, NULL);
169 if (pixGetDepth(pixs) != 1)
170 return (
SEL *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
171 if (nhlines < 1 && nvlines < 1)
172 return (
SEL *)ERROR_PTR(
"nvlines and nhlines both < 1", __func__, NULL);
175 distance = DefaultDistanceToBoundary;
177 minlength = DefaultMinRunlength;
178 if (distance > MaxDistanceToBoundary) {
179 L_WARNING(
"distance too large; setting to max value\n", __func__);
180 distance = MaxDistanceToBoundary;
186 return (
SEL *)ERROR_PTR(
"pixt1 not made", __func__, NULL);
187 ws = pixGetWidth(pixt1);
188 hs = pixGetHeight(pixt1);
194 if (toppix || botpix || leftpix || rightpix) {
199 if (toppix < distance + minlength)
200 L_WARNING(
"no miss elements in added top pixels\n", __func__);
204 if (botpix < distance + minlength)
205 L_WARNING(
"no miss elements in added bot pixels\n", __func__);
210 if (leftpix < distance + minlength)
211 L_WARNING(
"no miss elements in added left pixels\n", __func__);
215 if (rightpix < distance + minlength)
216 L_WARNING(
"no miss elements in added right pixels\n", __func__);
230 distance, distance, SEL_HIT);
231 pixfg =
pixErode(NULL, pixt2, seld);
241 delh = (l_float32)h / (l_float32)(nhlines + 1);
242 for (i = 0, y = 0; i < nhlines; i++) {
243 y += (l_int32)(delh + 0.5);
248 for (j = 0; j < nh; j++) {
252 for (j = 0; j < nm; j++) {
261 delw = (l_float32)w / (l_float32)(nvlines + 1);
262 for (i = 0, x = 0; i < nvlines; i++) {
263 x += (l_int32)(delw + 0.5);
268 for (j = 0; j < nh; j++) {
272 for (j = 0; j < nm; j++) {
284 for (i = 0; i < nh; i++) {
289 for (i = 0; i < nm; i++) {
346 l_int32 ws, hs, w, h, x, y, i, j, thresh;
348 PIX *pixt1, *pixt2, *pixfg, *pixbg;
351 if (ppixe) *ppixe = NULL;
353 return (
SEL *)ERROR_PTR(
"pixs not defined", __func__, NULL);
354 if (pixGetDepth(pixs) != 1)
355 return (
SEL *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
356 if (hitfract <= 0.0 && missfract <= 0.0)
357 return (
SEL *)ERROR_PTR(
"no hits or misses", __func__, NULL);
358 if (hitfract > 1.0 || missfract > 1.0)
359 return (
SEL *)ERROR_PTR(
"fraction can't be > 1.0", __func__, NULL);
362 distance = DefaultDistanceToBoundary;
363 if (distance > MaxDistanceToBoundary) {
364 L_WARNING(
"distance too large; setting to max value\n", __func__);
365 distance = MaxDistanceToBoundary;
371 return (
SEL *)ERROR_PTR(
"pixt1 not made", __func__, NULL);
372 ws = pixGetWidth(pixt1);
373 hs = pixGetHeight(pixt1);
379 if (toppix || botpix || leftpix || rightpix) {
405 distance, distance, SEL_HIT);
406 pixfg =
pixErode(NULL, pixt2, seld);
414 if (hitfract > 0.0) {
415 thresh = (l_int32)(hitfract * (l_float64)RAND_MAX);
416 for (i = 0; i < h; i++) {
417 for (j = 0; j < w; j++) {
426 if (missfract > 0.0) {
427 thresh = (l_int32)(missfract * (l_float64)RAND_MAX);
428 for (i = 0; i < h; i++) {
429 for (j = 0; j < w; j++) {
498 l_int32 ws, hs, w, h, x, y, ix, iy, i, npt;
499 PIX *pixt1, *pixt2, *pixt3, *pixfg, *pixbg;
500 SEL *selh, *selm, *sel_3, *sel;
503 if (ppixe) *ppixe = NULL;
505 return (
SEL *)ERROR_PTR(
"pixs not defined", __func__, NULL);
506 if (pixGetDepth(pixs) != 1)
507 return (
SEL *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
508 if (hitdist < 0 || hitdist > 4 || missdist < 0 || missdist > 4)
509 return (
SEL *)ERROR_PTR(
"dist not in {0 .. 4}", __func__, NULL);
510 if (hitskip < 0 && missskip < 0)
511 return (
SEL *)ERROR_PTR(
"no hits or misses", __func__, NULL);
516 return (
SEL *)ERROR_PTR(
"pixt1 not made", __func__, NULL);
517 ws = pixGetWidth(pixt1);
518 hs = pixGetHeight(pixt1);
524 if (topflag || botflag || leftflag || rightflag) {
553 hitdist, hitdist, SEL_HIT);
554 pixt3 =
pixErode(NULL, pixt2, selh);
555 pixfg =
pixErode(NULL, pixt3, sel_3);
556 pixXor(pixfg, pixfg, pixt3);
564 missdist, missdist, SEL_HIT);
567 pixXor(pixbg, pixbg, pixt3);
580 for (i = 0; i < npt; i++) {
587 for (i = 0; i < npt; i++) {
637 l_int32 w, h, i, r, nruns, len;
641 return (
NUMA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
642 if (pixGetDepth(pixs) != 1)
643 return (
NUMA *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
644 if (x != -1 && y != -1)
645 return (
NUMA *)ERROR_PTR(
"x or y must be -1", __func__, NULL);
646 if (x == -1 && y == -1)
647 return (
NUMA *)ERROR_PTR(
"x or y cannot both be -1", __func__, NULL);
650 return (
NUMA *)ERROR_PTR(
"nad not made", __func__, NULL);
651 w = pixGetWidth(pixs);
652 h = pixGetHeight(pixs);
666 for (i = 0; i < nruns; i++) {
673 if (len >= minlength)
708 l_int32 w, h, x, y, npts;
709 l_int32 i, runlen, preval;
715 return (
NUMA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
716 if (pixGetDepth(pixs) != 1)
717 return (
NUMA *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
719 w = pixGetWidth(pixs);
720 h = pixGetHeight(pixs);
721 if (x1 < 0 || x1 >= w)
722 return (
NUMA *)ERROR_PTR(
"x1 not valid", __func__, NULL);
723 if (x2 < 0 || x2 >= w)
724 return (
NUMA *)ERROR_PTR(
"x2 not valid", __func__, NULL);
725 if (y1 < 0 || y1 >= h)
726 return (
NUMA *)ERROR_PTR(
"y1 not valid", __func__, NULL);
727 if (y2 < 0 || y2 >= h)
728 return (
NUMA *)ERROR_PTR(
"y2 not valid", __func__, NULL);
731 return (
NUMA *)ERROR_PTR(
"pta not made", __func__, NULL);
734 return (
NUMA *)ERROR_PTR(
"pta has no pts", __func__, NULL);
738 return (
NUMA *)ERROR_PTR(
"numa not made", __func__, NULL);
741 for (i = 0; i < npts; i++) {
798 l_int32 x, y, xn, yn, xs, ys, xa, ya, count;
803 return (
PTA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
804 if (pixGetDepth(pixs) != 1)
805 return (
PTA *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
807 return (
PTA *)ERROR_PTR(
"skip < 0", __func__, NULL);
866 l_int32 w, h, i, xa, ya, found;
867 l_int32 xdel[] = {-1, 0, 1, 0, -1, 1, 1, -1};
868 l_int32 ydel[] = {0, 1, 0, -1, 1, 1, -1, -1};
872 return ERROR_INT(
"pixs not defined", __func__, 0);
873 if (pixGetDepth(pixs) != 1)
874 return ERROR_INT(
"pixs not 1 bpp", __func__, 0);
875 w = pixGetWidth(pixs);
876 h = pixGetHeight(pixs);
878 for (i = 0; i < 8; i++) {
881 if (xa < 0 || xa >= w || ya < 0 || ya >= h)
928 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
929 if (pixGetDepth(pixs) != 1)
930 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
932 return (
PIX *)ERROR_PTR(
"sel not defined", __func__, NULL);
934 if (scalefactor <= 0)
935 scalefactor = DefaultSelScalefactor;
936 if (scalefactor > MaxSelScalefactor) {
937 L_WARNING(
"scalefactor too large; using max value\n", __func__);
938 scalefactor = MaxSelScalefactor;
947 (hitcolor >> 8) & 0xff);
949 (misscolor >> 8) & 0xff);
953 for (i = 0; i < sel->
sy; i++) {
954 for (j = 0; j < sel->
sx; j++) {
956 if (type == SEL_DONT_CARE)
966 fscale = (l_float32)scalefactor;
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
l_ok pixcmapAddColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapAddColor()
l_int32 nextOnPixelInRaster(PIX *pixs, l_int32 xstart, l_int32 ystart, l_int32 *px, l_int32 *py)
nextOnPixelInRaster()
PTA * generatePtaLine(l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2)
generatePtaLine()
PIX * pixErode(PIX *pixd, PIX *pixs, SEL *sel)
pixErode()
PIX * pixDilate(PIX *pixd, PIX *pixs, SEL *sel)
pixDilate()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
NUMA * numaCreate(l_int32 n)
numaCreate()
void numaDestroy(NUMA **pna)
numaDestroy()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
void pixDestroy(PIX **ppix)
pixDestroy()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
l_ok pixSetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 val)
pixSetPixel()
l_ok pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
PIX * pixXor(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixXor()
l_ok pixClipToForeground(PIX *pixs, PIX **ppixd, BOX **pbox)
pixClipToForeground()
PIX * pixConvert1To8(PIX *pixd, PIX *pixs, l_uint8 val0, l_uint8 val1)
pixConvert1To8()
l_ok ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
l_ok ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
PTA * ptaCreate(l_int32 n)
ptaCreate()
void ptaDestroy(PTA **ppta)
ptaDestroy()
PTA * ptaGetPixelsFromPix(PIX *pixs, BOX *box)
ptaGetPixelsFromPix()
l_ok pixRasterop(PIX *pixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, PIX *pixs, l_int32 sx, l_int32 sy)
pixRasterop()
PIX * pixScaleBySampling(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleBySampling()
void selDestroy(SEL **psel)
selDestroy()
l_ok selSetElement(SEL *sel, l_int32 row, l_int32 col, l_int32 type)
selSetElement()
l_ok selGetElement(SEL *sel, l_int32 row, l_int32 col, l_int32 *ptype)
selGetElement()
SEL * selCreateBrick(l_int32 h, l_int32 w, l_int32 cy, l_int32 cx, l_int32 type)
selCreateBrick()
SEL * pixGenerateSelBoundary(PIX *pixs, l_int32 hitdist, l_int32 missdist, l_int32 hitskip, l_int32 missskip, l_int32 topflag, l_int32 botflag, l_int32 leftflag, l_int32 rightflag, PIX **ppixe)
pixGenerateSelBoundary()
NUMA * pixGetRunCentersOnLine(PIX *pixs, l_int32 x, l_int32 y, l_int32 minlength)
pixGetRunCentersOnLine()
PTA * pixSubsampleBoundaryPixels(PIX *pixs, l_int32 skip)
pixSubsampleBoundaryPixels()
SEL * pixGenerateSelWithRuns(PIX *pixs, l_int32 nhlines, l_int32 nvlines, l_int32 distance, l_int32 minlength, l_int32 toppix, l_int32 botpix, l_int32 leftpix, l_int32 rightpix, PIX **ppixe)
pixGenerateSelWithRuns()
PIX * pixDisplayHitMissSel(PIX *pixs, SEL *sel, l_int32 scalefactor, l_uint32 hitcolor, l_uint32 misscolor)
pixDisplayHitMissSel()
SEL * pixGenerateSelRandom(PIX *pixs, l_float32 hitfract, l_float32 missfract, l_int32 distance, l_int32 toppix, l_int32 botpix, l_int32 leftpix, l_int32 rightpix, PIX **ppixe)
pixGenerateSelRandom()
l_int32 adjacentOnPixelInRaster(PIX *pixs, l_int32 x, l_int32 y, l_int32 *pxa, l_int32 *pya)
adjacentOnPixelInRaster()
NUMA * pixGetRunsOnLine(PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2)
pixGetRunsOnLine()