From 34e0d017abf7326f13902e1f5b59f2f8404febf8 Mon Sep 17 00:00:00 2001 From: Egor Pugin Date: Thu, 1 Apr 2021 19:15:58 +0300 Subject: [PATCH] Add Image::operator&=(). --- src/ccmain/pagesegmain.cpp | 4 ++-- src/ccstruct/image.cpp | 16 +++++++++++++++- src/ccstruct/image.h | 7 ++++++- src/textord/imagefind.cpp | 4 ++-- src/textord/linefind.cpp | 8 ++++---- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/ccmain/pagesegmain.cpp b/src/ccmain/pagesegmain.cpp index 04c9029e2..f3edc81ae 100644 --- a/src/ccmain/pagesegmain.cpp +++ b/src/ccmain/pagesegmain.cpp @@ -65,7 +65,7 @@ static Image RemoveEnclosingCircle(Image pixs) { pixSeedfillBinary(pixc, pixc, pixsi, 4); pixInvert(pixc, pixc); pixsi.destroy(); - Image pixt = pixAnd(nullptr, pixs, pixc); + Image pixt = pixs & pixc; l_int32 max_count; pixCountConnComp(pixt, 8, &max_count); // The count has to go up before we start looking for the minimum. @@ -74,7 +74,7 @@ static Image RemoveEnclosingCircle(Image pixs) { for (int i = 1; i < kMaxCircleErosions; i++) { pixt.destroy(); pixErodeBrick(pixc, pixc, 3, 3); - pixt = pixAnd(nullptr, pixs, pixc); + pixt = pixs & pixc; l_int32 count; pixCountConnComp(pixt, 8, &count); if (i == 1 || count > max_count) { diff --git a/src/ccstruct/image.cpp b/src/ccstruct/image.cpp index 7116c9bb2..bb24b1109 100644 --- a/src/ccstruct/image.cpp +++ b/src/ccstruct/image.cpp @@ -39,8 +39,22 @@ bool Image::isZero() const { return r == 1; } -void Image::operator|=(Image i) { +Image Image::operator|(Image i) const { + return pixOr(nullptr, pix_, i); +} + +Image &Image::operator|=(Image i) { pixOr(pix_, pix_, i); + return *this; +} + +Image Image::operator&(Image i) const { + return pixAnd(nullptr, pix_, i); +} + +Image &Image::operator&=(Image i) { + pixAnd(pix_, pix_, i); + return *this; } } diff --git a/src/ccstruct/image.h b/src/ccstruct/image.h index f0610f93e..192884fe1 100644 --- a/src/ccstruct/image.h +++ b/src/ccstruct/image.h @@ -39,7 +39,12 @@ public: Image copy() const; // does full copy void destroy(); bool isZero() const; - void operator|=(Image); + + // ops + Image operator|(Image) const; + Image &operator|=(Image); + Image operator&(Image) const; + Image &operator&=(Image); }; } // namespace tesseract diff --git a/src/textord/imagefind.cpp b/src/textord/imagefind.cpp index af13acd49..94e808073 100644 --- a/src/textord/imagefind.cpp +++ b/src/textord/imagefind.cpp @@ -129,7 +129,7 @@ Image ImageFind::FindImages(Image pix, DebugPixa *pixa_debug) { pixa_debug->AddPix(pixcoarsemask, "CoarseMask"); } // Combine the coarse and fine image masks. - pixAnd(pixcoarsemask, pixcoarsemask, pixfinemask); + pixcoarsemask &= pixfinemask; pixfinemask.destroy(); // Dilate a bit to make sure we get everything. pixDilateBrick(pixcoarsemask, pixcoarsemask, 3, 3); @@ -139,7 +139,7 @@ Image ImageFind::FindImages(Image pix, DebugPixa *pixa_debug) { pixa_debug->AddPix(pixmask, "MaskDilated"); } // And the image mask with the line and bar remover. - pixAnd(pixht, pixht, pixmask); + pixht &= pixmask; pixmask.destroy(); if (textord_tabfind_show_images && pixa_debug != nullptr) { pixa_debug->AddPix(pixht, "FinalMask"); diff --git a/src/textord/linefind.cpp b/src/textord/linefind.cpp index f76167c8d..63db8daee 100644 --- a/src/textord/linefind.cpp +++ b/src/textord/linefind.cpp @@ -259,7 +259,7 @@ void LineFinder::FindAndRemoveLines(int resolution, bool debug, Image pix, int * if (pix_hline != nullptr) { // Recompute intersections and re-filter false positive h-lines. if (pix_vline != nullptr) { - pixAnd(pix_intersections, pix_vline, pix_hline); + pix_intersections = pix_vline & pix_hline; } else { pix_intersections.destroy(); } @@ -278,7 +278,7 @@ void LineFinder::FindAndRemoveLines(int resolution, bool debug, Image pix, int * if (pix_vline != nullptr && pix_hline != nullptr) { // Remove joins (intersections) where lines cross, and the residue. // Recalculate the intersections, since some lines have been deleted. - pixAnd(pix_intersections, pix_vline, pix_hline); + pix_intersections = pix_vline & pix_hline; // Fatten up the intersections and seed-fill to get the intersection // residue. Image pix_join_residue = pixDilateBrick(nullptr, pix_intersections, 5, 5); @@ -483,7 +483,7 @@ void LineFinder::FindLineVectors(const ICOORD &bleft, const ICOORD &tright, static Image FilterMusic(int resolution, Image pix_closed, Image pix_vline, Image pix_hline, bool &v_empty, bool &h_empty) { int max_stave_height = static_cast(resolution * kMaxStaveHeight); - Image intersection_pix = pixAnd(nullptr, pix_vline, pix_hline); + Image intersection_pix = pix_vline & pix_hline; Boxa *boxa = pixConnComp(pix_vline, nullptr, 8); // Iterate over the boxes to find music bars. int nboxes = boxaGetCount(boxa); @@ -637,7 +637,7 @@ void LineFinder::GetLineMasks(int resolution, Image src_pix, Image *pix_vline, I if (!h_empty) { pixSubtract(pix_nonlines, pix_nonlines, *pix_hline); // Intersections are a useful indicator for likelihood of being a line. - *pix_intersections = pixAnd(nullptr, *pix_vline, *pix_hline); + *pix_intersections = *pix_vline & *pix_hline; // Candidate vlines are not hlines (apart from the intersections) // and vice versa. extra_non_hlines = pixSubtract(nullptr, *pix_vline, *pix_intersections);