Skip to content

Commit

Permalink
Implement distort_image in text2image - default false
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreeshrii committed Feb 22, 2019
1 parent 49ed3a7 commit 2aded47
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/training/degradeimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ 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);
// pix = input;
// input = PrepareDistortedPix(pix, false, true, true, true, true,
// 1, randomizer, nullptr);
// pixDestroy(&pix);

return input;
}
Expand Down Expand Up @@ -215,7 +215,7 @@ 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)
if (invert && randomizer->SignedRand(1.0) < -0.9)
pixInvert(distorted, distorted);
return distorted;
}
Expand Down
28 changes: 28 additions & 0 deletions src/training/text2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ BOOL_PARAM_FLAG(rotate_image, true, "Rotate the image in a random way.");
// Degradation to apply to the image.
INT_PARAM_FLAG(exposure, 0, "Exposure level in photocopier");

// Distort the rendered image by various means according to the bool flags.
BOOL_PARAM_FLAG(distort_image, false,
"Degrade rendered image with noise, blur, invert.");

// Distortion to apply to the image.
BOOL_PARAM_FLAG(invert, true, "Invert the image");

// Distortion to apply to the image.
BOOL_PARAM_FLAG(white_noise, true, "Add Gaussian Noise");

// Distortion to apply to the image.
BOOL_PARAM_FLAG(smooth_noise, true, "Smoothen Noise");

// Distortion to apply to the image.
BOOL_PARAM_FLAG(blur, true, "Blur the image");

// Distortion to apply to the image.
//BOOL_PARAM_FLAG(perspective, false, "Generate Perspective Distortion");

// Distortion to apply to the image.
//INT_PARAM_FLAG(box_reduction, 0, "Integer reduction factor box_scale");

// Output image resolution.
INT_PARAM_FLAG(resolution, 300, "Pixels per inch");

Expand Down Expand Up @@ -619,6 +641,12 @@ static int Main() {
pix = DegradeImage(pix, FLAGS_exposure, &randomizer,
FLAGS_rotate_image ? &rotation : nullptr);
}
if (FLAGS_distort_image) {
//Todo: perspective is set to false and box_reduction to 1.
pix = PrepareDistortedPix(pix, false, FLAGS_invert,
FLAGS_white_noise, FLAGS_smooth_noise, FLAGS_blur,
1, &randomizer, nullptr);
}
render.RotatePageBoxes(rotation);

if (pass == 0) {
Expand Down

0 comments on commit 2aded47

Please sign in to comment.