Skip to content

Commit

Permalink
implement PrepareDistortedPix as part of DegradeImage
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreeshrii committed Feb 21, 2019
1 parent 9644b58 commit 49ed3a7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/training/degradeimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand All @@ -181,8 +188,6 @@ Pix* PrepareDistortedPix(const Pix* pix, bool perspective, bool invert,
GenericVector<TBOX>* boxes) {
Pix* distorted = pixCopy(nullptr, const_cast<Pix*>(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.
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 49ed3a7

Please sign in to comment.