From 49ed3a72d4bf5b027328c2fe97b4606ca54173a9 Mon Sep 17 00:00:00 2001 From: Shree Date: Thu, 21 Feb 2019 14:48:29 +0000 Subject: [PATCH] implement PrepareDistortedPix as part of DegradeImage --- src/training/degradeimage.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/training/degradeimage.cpp b/src/training/degradeimage.cpp index 3f449cc7ca..9044d0419d 100644 --- a/src/training/degradeimage.cpp +++ b/src/training/degradeimage.cpp @@ -95,6 +95,7 @@ Pix* DegradeImage(Pix* input, int exposure, TRand* randomizer, input = pix; int width = pixGetWidth(input); int height = pixGetHeight(input); + if (exposure >= 2) { // An erosion simulates the spreading darkening of a dark copy. // This is backwards to binary morphology, @@ -167,6 +168,12 @@ Pix* DegradeImage(Pix* input, int exposure, TRand* randomizer, } data += input->wpl; } + + pix = input; + input = PrepareDistortedPix(pix, false, true, true, true, true, + 1, randomizer, nullptr); + pixDestroy(&pix); + return input; } @@ -181,8 +188,6 @@ Pix* PrepareDistortedPix(const Pix* pix, bool perspective, bool invert, GenericVector* boxes) { Pix* distorted = pixCopy(nullptr, const_cast(pix)); // Things to do to synthetic training data. - if (invert && randomizer->SignedRand(1.0) < 0) - pixInvert(distorted, distorted); if ((white_noise || smooth_noise) && randomizer->SignedRand(1.0) > 0.0) { // TODO(rays) Cook noise in a more thread-safe manner than rand(). // Attempt to make the sequences reproducible. @@ -210,6 +215,8 @@ Pix* PrepareDistortedPix(const Pix* pix, bool perspective, bool invert, (*boxes)[b].set_right((*boxes)[b].left() + 1); } } + if (invert && randomizer->SignedRand(1.0) < -0.5) + pixInvert(distorted, distorted); return distorted; }