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