Skip to content

Commit 49ed3a7

Browse files
committed
implement PrepareDistortedPix as part of DegradeImage
1 parent 9644b58 commit 49ed3a7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/training/degradeimage.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Pix* DegradeImage(Pix* input, int exposure, TRand* randomizer,
9595
input = pix;
9696
int width = pixGetWidth(input);
9797
int height = pixGetHeight(input);
98+
9899
if (exposure >= 2) {
99100
// An erosion simulates the spreading darkening of a dark copy.
100101
// This is backwards to binary morphology,
@@ -167,6 +168,12 @@ Pix* DegradeImage(Pix* input, int exposure, TRand* randomizer,
167168
}
168169
data += input->wpl;
169170
}
171+
172+
pix = input;
173+
input = PrepareDistortedPix(pix, false, true, true, true, true,
174+
1, randomizer, nullptr);
175+
pixDestroy(&pix);
176+
170177
return input;
171178
}
172179

@@ -181,8 +188,6 @@ Pix* PrepareDistortedPix(const Pix* pix, bool perspective, bool invert,
181188
GenericVector<TBOX>* boxes) {
182189
Pix* distorted = pixCopy(nullptr, const_cast<Pix*>(pix));
183190
// Things to do to synthetic training data.
184-
if (invert && randomizer->SignedRand(1.0) < 0)
185-
pixInvert(distorted, distorted);
186191
if ((white_noise || smooth_noise) && randomizer->SignedRand(1.0) > 0.0) {
187192
// TODO(rays) Cook noise in a more thread-safe manner than rand().
188193
// Attempt to make the sequences reproducible.
@@ -210,6 +215,8 @@ Pix* PrepareDistortedPix(const Pix* pix, bool perspective, bool invert,
210215
(*boxes)[b].set_right((*boxes)[b].left() + 1);
211216
}
212217
}
218+
if (invert && randomizer->SignedRand(1.0) < -0.5)
219+
pixInvert(distorted, distorted);
213220
return distorted;
214221
}
215222

0 commit comments

Comments
 (0)