MCPcopy Create free account
hub / github.com/creatale/node-dv / pixSplitComponentIntoBoxa

Function pixSplitComponentIntoBoxa

deps/leptonica/src/boxfunc3.c:942–1030  ·  view source on GitHub ↗

! * \brief pixSplitComponentIntoBoxa() * * \param[in] pix 1 bpp * \param[in] box [optional] location of pix w/rt an origin * \param[in] minsum minimum pixels to trigger propagation * \param[in] skipdist distance before computing sum for propagation * \param[in] delta difference required to stop propagation * \param[in] maxbg maximum number of allowed bg pixels in ref s

Source from the content-addressed store, hash-verified

940 * </pre>
941 */
942BOXA *
943pixSplitComponentIntoBoxa(PIX *pix,
944 BOX *box,
945 l_int32 minsum,
946 l_int32 skipdist,
947 l_int32 delta,
948 l_int32 maxbg,
949 l_int32 maxcomps,
950 l_int32 remainder)
951{
952l_int32 i, w, h, boxx, boxy, bx, by, bw, bh, maxdir, maxscore;
953l_int32 iter;
954BOX *boxs; /* shrinks as rectangular regions are removed */
955BOX *boxt1, *boxt2, *boxt3;
956BOXA *boxat; /* stores rectangle data for each side in an iteration */
957BOXA *boxad;
958NUMA *nascore, *nas;
959PIX *pixs;
960
961 PROCNAME("pixSplitComponentIntoBoxa");
962
963 if (!pix || pixGetDepth(pix) != 1)
964 return (BOXA *)ERROR_PTR("pix undefined or not 1 bpp", procName, NULL);
965
966 pixs = pixCopy(NULL, pix);
967 pixGetDimensions(pixs, &w, &h, NULL);
968 if (box)
969 boxGetGeometry(box, &boxx, &boxy, NULL, NULL);
970 else
971 boxx = boxy = 0;
972 boxs = boxCreate(0, 0, w, h);
973 boxad = boxaCreate(0);
974
975 iter = 0;
976 while (boxs != NULL) {
977 boxGetGeometry(boxs, &bx, &by, &bw, &bh);
978 boxat = boxaCreate(4); /* potential rectangular regions */
979 nascore = numaCreate(4);
980 for (i = 0; i < 4; i++) {
981 pixSearchForRectangle(pixs, boxs, minsum, skipdist, delta, maxbg,
982 i, boxat, nascore);
983 }
984 nas = numaGetSortIndex(nascore, L_SORT_DECREASING);
985 numaGetIValue(nas, 0, &maxdir);
986 numaGetIValue(nascore, maxdir, &maxscore);
987#if DEBUG_SPLIT
988 fprintf(stderr, "Iteration: %d\n", iter);
989 boxPrintStreamInfo(stderr, boxs);
990 boxaWriteStream(stderr, boxat);
991 fprintf(stderr, "\nmaxdir = %d, maxscore = %d\n\n", maxdir, maxscore);
992#endif /* DEBUG_SPLIT */
993 if (maxscore > 0) { /* accept this */
994 boxt1 = boxaGetBox(boxat, maxdir, L_CLONE);
995 boxt2 = boxTransform(boxt1, boxx, boxy, 1.0, 1.0);
996 boxaAddBox(boxad, boxt2, L_INSERT);
997 pixClearInRect(pixs, boxt1);
998 boxDestroy(&boxt1);
999 pixClipBoxToForeground(pixs, boxs, NULL, &boxt3);

Callers 1

pixSplitIntoBoxaFunction · 0.85

Calls 15

pixGetDepthFunction · 0.85
pixCopyFunction · 0.85
pixGetDimensionsFunction · 0.85
boxGetGeometryFunction · 0.85
boxCreateFunction · 0.85
boxaCreateFunction · 0.85
numaCreateFunction · 0.85
pixSearchForRectangleFunction · 0.85
numaGetSortIndexFunction · 0.85
numaGetIValueFunction · 0.85
boxPrintStreamInfoFunction · 0.85
boxaWriteStreamFunction · 0.85

Tested by

no test coverage detected