252 {
253 auto width = pixGetWidth(pix);
254 auto height = pixGetHeight(pix);
255
256
257
258
260 return pixCreate(width, height, 1);
261 }
262
263
264 Image pixr = pixReduceRankBinaryCascade(pix, 1, 0, 0, 0);
265 if (textord_tabfind_show_images && pixa_debug != nullptr) {
266 pixa_debug->AddPix(pixr, "CascadeReduced");
267 }
268
269
270 l_int32 ht_found = 0;
271 Pixa *pixadb = (textord_tabfind_show_images && pixa_debug != nullptr) ? pixaCreate(0) : nullptr;
272 Image pixht2 = pixGenerateHalftoneMask(pixr, nullptr, &ht_found, pixadb);
273 if (pixadb) {
274 Image pixdb = pixaDisplayTiledInColumns(pixadb, 3, 1.0, 20, 2);
275 if (textord_tabfind_show_images && pixa_debug != nullptr) {
276 pixa_debug->AddPix(pixdb, "HalftoneMask");
277 }
278 pixdb.destroy();
279 pixaDestroy(&pixadb);
280 }
281 pixr.destroy();
282 if (!ht_found && pixht2 != nullptr) {
283 pixht2.destroy();
284 }
285 if (pixht2 == nullptr) {
286 return pixCreate(width, height, 1);
287 }
288
289
290 Image pixht = pixExpandReplicate(pixht2, 2);
291 if (textord_tabfind_show_images && pixa_debug != nullptr) {
292 pixa_debug->AddPix(pixht, "HalftoneReplicated");
293 }
294 pixht2.destroy();
295
296
297 Image pixt = pixSeedfillBinary(nullptr, pixht, pix, 8);
298 pixht |= pixt;
299 pixt.destroy();
300
301
302 Image pixfinemask = pixReduceRankBinaryCascade(pixht, 1, 1, 3, 3);
303 pixDilateBrick(pixfinemask, pixfinemask, 5, 5);
304 if (textord_tabfind_show_images && pixa_debug != nullptr) {
305 pixa_debug->AddPix(pixfinemask, "FineMask");
306 }
307 Image pixreduced = pixReduceRankBinaryCascade(pixht, 1, 1, 1, 1);
308 Image pixreduced2 = pixReduceRankBinaryCascade(pixreduced, 3, 3, 3, 0);
309 pixreduced.destroy();
310 pixDilateBrick(pixreduced2, pixreduced2, 5, 5);
311 Image pixcoarsemask = pixExpandReplicate(pixreduced2, 8);
312 pixreduced2.destroy();
313 if (textord_tabfind_show_images && pixa_debug != nullptr) {
314 pixa_debug->AddPix(pixcoarsemask, "CoarseMask");
315 }
316
317 pixcoarsemask &= pixfinemask;
318 pixfinemask.destroy();
319
320 pixDilateBrick(pixcoarsemask, pixcoarsemask, 3, 3);
321 Image pixmask = pixExpandReplicate(pixcoarsemask, 16);
322 pixcoarsemask.destroy();
323 if (textord_tabfind_show_images && pixa_debug != nullptr) {
324 pixa_debug->AddPix(pixmask, "MaskDilated");
325 }
326
327 pixht &= pixmask;
328 pixmask.destroy();
329 if (textord_tabfind_show_images && pixa_debug != nullptr) {
330 pixa_debug->AddPix(pixht, "FinalMask");
331 }
332
333 Image result = pixCreate(width, height, 1);
334 result |= pixht;
335 pixht.destroy();
336 return result;
337}
const int kMinImageFindSize