121l_int32 i, n, index, w, h, xb, yb, wb, hb;
123PIX *pix1, *pix2, *pixd;
126 if (!pixs || pixGetDepth(pixs) != 1)
127 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
128 if (connect != 4 && connect != 8)
129 return (
PIX *)ERROR_PTR(
"connectivity must be 4 or 8", __func__, NULL);
130 if (depth != 0 && depth != 8 && depth != 16 && depth != 32)
131 return (
PIX *)ERROR_PTR(
"depth must be 0, 8, 16 or 32", __func__, NULL);
133 boxa = pixConnComp(pixs, &pixa, connect);
134 n = pixaGetCount(pixa);
136 pixGetDimensions(pixs, &w, &h, NULL);
145 pixd = pixCreate(w, h, depth);
153 for (i = 0; i < n; i++) {
154 pixaGetBoxGeometry(pixa, i, &xb, &yb, &wb, &hb);
155 pix1 = pixaGetPix(pixa, i,
L_CLONE);
157 index = 1 + (i % 254);
158 pix2 = pixConvert1To8(NULL, pix1, 0, index);
159 }
else if (depth == 16) {
160 index = 1 + (i % 0xfffe);
161 pix2 = pixConvert1To16(NULL, pix1, 0, index);
164 pix2 = pixConvert1To32(NULL, pix1, 0, index);
166 pixRasterop(pixd, xb, yb, wb, hb,
PIX_PAINT, pix2, 0, 0);
198l_int32 i, n, npix, w, h, xb, yb, wb, hb;
201PIX *pix1, *pix2, *pixd;
204 if (!pixs || pixGetDepth(pixs) != 1)
205 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
206 if (connect != 4 && connect != 8)
207 return (
PIX *)ERROR_PTR(
"connectivity must be 4 or 8", __func__, NULL);
209 boxa = pixConnComp(pixs, &pixa, connect);
210 n = pixaGetCount(pixa);
212 pixGetDimensions(pixs, &w, &h, NULL);
213 pixd = pixCreate(w, h, 32);
221 tab8 = makePixelSumTab8();
222 for (i = 0; i < n; i++) {
223 pixaGetBoxGeometry(pixa, i, &xb, &yb, &wb, &hb);
224 pix1 = pixaGetPix(pixa, i,
L_CLONE);
225 pixCountPixels(pix1, &npix, tab8);
226 pix2 = pixConvert1To32(NULL, pix1, 0, npix);
227 pixRasterop(pixd, xb, yb, wb, hb,
PIX_PAINT, pix2, 0, 0);
272l_int32 empty, w, h, ncc;
277 if (ppixd) *ppixd = NULL;
278 if (pptaa) *pptaa = NULL;
280 if (!ppixd || !pptaa || !pncc)
281 return ERROR_INT(
"&pixd, &ptaa, &ncc not all defined", __func__, 1);
282 if (!pixs || pixGetDepth(pixs) != 1)
283 return ERROR_INT(
"pixs undefined or not 1 bpp", __func__, 1);
284 if (conn != 4 && conn != 8)
285 return ERROR_INT(
"connectivity must be 4 or 8", __func__, 1);
287 pixGetDimensions(pixs, &w, &h, NULL);
288 pixZero(pixs, &empty);
290 *ppixd = pixCreate(w, h, 32);
291 pixSetSpp(*ppixd, 1);
292 pixSetSpecial(*ppixd, conn);
293 *pptaa = ptaaCreate(0);
301 return ERROR_INT(
"pixd not made", __func__, 1);
302 pixSetSpecial(pixd, conn);
304 if ((ptaa = ptaaIndexLabeledPixels(pixd, &ncc)) == NULL)
305 return ERROR_INT(
"ptaa not made", __func__, 1);
355l_int32 conn, i, j, w, h, count, nvals, ns, firstindex;
360 if (!pixs || pixGetDepth(pixs) != 32)
361 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
363 return ERROR_INT(
"ptaa not defined", __func__, 1);
365 return ERROR_INT(
"&ncc not defined", __func__, 1);
367 if (conn != 4 && conn != 8)
368 return ERROR_INT(
"connectivity must be 4 or 8", __func__, 1);
369 pixGetDimensions(pixs, &w, &h, NULL);
371 return ERROR_INT(
"invalid x pixel location", __func__, 1);
373 return ERROR_INT(
"invalid y pixel location", __func__, 1);
375 pixGetPixel(pixs, x, y, &val);
388 count = ptaaGetCount(ptaa);
389 pixSetPixel(pixs, x, y, count);
391 ptaAddPt(ptas, x, y);
400 firstindex = neigh[0];
401 pixSetPixel(pixs, x, y, firstindex);
402 ptaaAddPt(ptaa, neigh[0], x, y);
405 lept_stderr(
"nvals = %d: neigh = (%d)\n", nvals, neigh[0]);
418 if (debug >= 1 && debug <= 2) {
419 lept_stderr(
"nvals = %d: neigh = (%d,%d)\n", nvals,
422 }
else if (nvals == 3) {
423 if (debug >= 1 && debug <= 3) {
424 lept_stderr(
"nvals = %d: neigh = (%d,%d,%d)\n", nvals,
425 neigh[0], neigh[1], neigh[2]);
428 if (debug >= 1 && debug <= 4) {
429 lept_stderr(
"nvals = %d: neigh = (%d,%d,%d,%d)\n", nvals,
430 neigh[0], neigh[1], neigh[2], neigh[3]);
433 ptad = ptaaGetPta(ptaa, firstindex,
L_CLONE);
434 for (i = 1; i < nvals; i++) {
435 ptas = ptaaGetPta(ptaa, neigh[i],
L_CLONE);
436 ns = ptaGetCount(ptas);
437 for (j = 0; j < ns; j++) {
438 ptaGetPt(ptas, j, &x, &y);
439 pixSetPixel(pixs, x, y, firstindex);
441 ptaJoin(ptad, ptas, 0, -1);
443 ptaDestroy(&ptaa->
pta[neigh[i]]);
483l_int32 i, npt, index;
492 if (pneigh) *pneigh = NULL;
493 if (pnvals) *pnvals = 0;
494 if (!pneigh || !pnvals)
495 return ERROR_INT(
"&neigh and &nvals not both defined", __func__, 1);
496 if (!pixs || pixGetDepth(pixs) < 8)
497 return ERROR_INT(
"pixs not defined or depth < 8", __func__, 1);
500 if ((pta = ptaGetNeighborPixLocs(pixs, x, y, conn)) == NULL)
501 return ERROR_INT(
"pta of neighbors not made", __func__, 1);
504 aset = l_asetCreate(L_UINT_TYPE);
505 npt = ptaGetCount(pta);
506 for (i = 0; i < npt; i++) {
507 ptaGetPt(pta, i, &fx, &fy);
508 pixGetPixel(pixs, (l_int32)fx, (l_int32)fy, &val);
510 l_asetInsert(aset, key);
516 node = l_asetGetFirst(aset);
519 val =
node->key.utype;
521 neigh[index++] = (l_int32)val;
526 *pneigh = (l_int32 *)LEPT_CALLOC(index,
sizeof(l_int32));
527 for (i = 0; i < index; i++)
528 (*pneigh)[i] = neigh[i];
532 l_asetDestroy(&aset);
562l_int32 w, h, w2, h2, wpls, wplr, wplg, wplb, wplcc, i, j, rval, gval, bval;
563l_float32 invw2, invh2;
564l_uint32 *datas, *datar, *datag, *datab, *datacc;
565l_uint32 *lines, *liner, *lineg, *lineb, *linecc;
566PIX *pix1, *pixcc, *pixr, *pixg, *pixb, *pixd;
568 if (!pixs || pixGetDepth(pixs) != 1)
569 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
574 pixGetDimensions(pixs, &w, &h, NULL);
577 invw2 = 255.0f / (l_float32)w2;
578 invh2 = 255.0f / (l_float32)h2;
585 pixr = pixCreate(w, h, 8);
586 pixg = pixCreate(w, h, 8);
587 pixb = pixCreate(w, h, 8);
588 wpls = pixGetWpl(pixs);
589 wplr = pixGetWpl(pixr);
590 wplg = pixGetWpl(pixg);
591 wplb = pixGetWpl(pixb);
592 wplcc = pixGetWpl(pixcc);
593 datas = pixGetData(pixs);
594 datar = pixGetData(pixr);
595 datag = pixGetData(pixg);
596 datab = pixGetData(pixb);
597 datacc = pixGetData(pixcc);
598 for (i = 0; i < h; i++) {
599 lines = datas + i * wpls;
600 liner = datar + i * wplr;
601 lineg = datag + i * wplg;
602 lineb = datab + i * wplb;
603 linecc = datacc+ i * wplcc;
604 for (j = 0; j < w; j++) {
607 rval = invh2 * L_ABS((l_float32)(i - h2));
608 gval = invw2 * L_ABS((l_float32)(j - w2));
610 rval = invw2 * L_ABS((l_float32)(j - w2));
611 gval = invh2 * L_ABS((l_float32)(i - h2));
619 pixd = pixCreateRGBImage(pixr, pixg, pixb);
l_int32 pixConnCompIncrAdd(PIX *pixs, PTAA *ptaa, l_int32 *pncc, l_float32 x, l_float32 y, l_int32 debug)
pixConnCompIncrAdd()
l_ok pixGetSortedNeighborValues(PIX *pixs, l_int32 x, l_int32 y, l_int32 conn, l_int32 **pneigh, l_int32 *pnvals)
pixGetSortedNeighborValues()