Add Image::operator&=().

This commit is contained in:
Egor Pugin 2021-04-01 19:15:58 +03:00
parent 9e3da4a724
commit 34e0d017ab
5 changed files with 29 additions and 10 deletions

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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

View File

@ -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");

View File

@ -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<int>(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);