62 {
63
66 return pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
67
68
69 Pix *pixr = pixReduceRankBinaryCascade(pix, 1, 0, 0, 0);
70 if (textord_tabfind_show_images && pixa_debug != nullptr)
71 pixa_debug->AddPix(pixr, "CascadeReduced");
72
73
74
75
76
77
80 pixDestroy(&pixr);
81 return pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
82 }
83
84 l_int32 ht_found = 0;
85 Pixa* pixadb = (textord_tabfind_show_images && pixa_debug != nullptr)
86 ? pixaCreate(0)
87 : nullptr;
88 Pix* pixht2 = pixGenerateHalftoneMask(pixr, nullptr, &ht_found, pixadb);
89 if (pixadb) {
90 Pix* pixdb = pixaDisplayTiledInColumns(pixadb, 3, 1.0, 20, 2);
91 if (textord_tabfind_show_images && pixa_debug != nullptr)
92 pixa_debug->AddPix(pixdb, "HalftoneMask");
93 pixDestroy(&pixdb);
94 pixaDestroy(&pixadb);
95 }
96 pixDestroy(&pixr);
97 if (!ht_found && pixht2 != nullptr)
98 pixDestroy(&pixht2);
99 if (pixht2 == nullptr)
100 return pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
101
102
103 Pix *pixht = pixExpandReplicate(pixht2, 2);
104 if (textord_tabfind_show_images && pixa_debug != nullptr)
105 pixa_debug->AddPix(pixht, "HalftoneReplicated");
106 pixDestroy(&pixht2);
107
108
109 Pix *pixt = pixSeedfillBinary(nullptr, pixht, pix, 8);
110 pixOr(pixht, pixht, pixt);
111 pixDestroy(&pixt);
112
113
114 Pix* pixfinemask = pixReduceRankBinaryCascade(pixht, 1, 1, 3, 3);
115 pixDilateBrick(pixfinemask, pixfinemask, 5, 5);
116 if (textord_tabfind_show_images && pixa_debug != nullptr)
117 pixa_debug->AddPix(pixfinemask, "FineMask");
118 Pix* pixreduced = pixReduceRankBinaryCascade(pixht, 1, 1, 1, 1);
119 Pix* pixreduced2 = pixReduceRankBinaryCascade(pixreduced, 3, 3, 3, 0);
120 pixDestroy(&pixreduced);
121 pixDilateBrick(pixreduced2, pixreduced2, 5, 5);
122 Pix* pixcoarsemask = pixExpandReplicate(pixreduced2, 8);
123 pixDestroy(&pixreduced2);
124 if (textord_tabfind_show_images && pixa_debug != nullptr)
125 pixa_debug->AddPix(pixcoarsemask, "CoarseMask");
126
127 pixAnd(pixcoarsemask, pixcoarsemask, pixfinemask);
128 pixDestroy(&pixfinemask);
129
130 pixDilateBrick(pixcoarsemask, pixcoarsemask, 3, 3);
131 Pix* pixmask = pixExpandReplicate(pixcoarsemask, 16);
132 pixDestroy(&pixcoarsemask);
133 if (textord_tabfind_show_images && pixa_debug != nullptr)
134 pixa_debug->AddPix(pixmask, "MaskDilated");
135
136 pixAnd(pixht, pixht, pixmask);
137 pixDestroy(&pixmask);
138 if (textord_tabfind_show_images && pixa_debug != nullptr)
139 pixa_debug->AddPix(pixht, "FinalMask");
140
141 Pix* result = pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
142 pixOr(result, result, pixht);
143 pixDestroy(&pixht);
144 return result;
145}
const int kMinImageFindSize