tesseract v5.3.3.20231005
degradeimage.h
Go to the documentation of this file.
1/**********************************************************************
2 * File: degradeimage.h
3 * Description: Function to degrade an image (usually of text) as if it
4 * has been printed and then scanned.
5 * Authors: Ray Smith
6 *
7 * (C) Copyright 2013, Google Inc.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 **********************************************************************/
19#ifndef TESSERACT_TRAINING_DEGRADEIMAGE_H_
20#define TESSERACT_TRAINING_DEGRADEIMAGE_H_
21
22#include <allheaders.h>
23#include "helpers.h" // For TRand.
24#include "rect.h"
25
26namespace tesseract {
27
28// Degrade the pix as if by a print/copy/scan cycle with exposure > 0
29// corresponding to darkening on the copier and <0 lighter and 0 not copied.
30// If rotation is not nullptr, the clockwise rotation in radians is saved there.
31// The input pix must be 8 bit grey. (Binary with values 0 and 255 is OK.)
32// The input image is destroyed and a different image returned.
33Image DegradeImage(Image input, int exposure, TRand *randomizer, float *rotation);
34
35// Creates and returns a Pix distorted by various means according to the bool
36// flags. If boxes is not nullptr, the boxes are resized/positioned according to
37// any spatial distortion and also by the integer reduction factor box_scale
38// so they will match what the network will output.
39// Returns nullptr on error. The returned Pix must be pixDestroyed.
40Image PrepareDistortedPix(const Image pix, bool perspective, bool invert, bool white_noise,
41 bool smooth_noise, bool blur, int box_reduction, TRand *randomizer,
42 std::vector<TBOX> *boxes);
43// Distorts anything that has a non-null pointer with the same pseudo-random
44// perspective distortion. Width and height only need to be set if there
45// is no pix. If there is a pix, then they will be taken from there.
46void GeneratePerspectiveDistortion(int width, int height, TRand *randomizer, Image *pix,
47 std::vector<TBOX> *boxes);
48// Computes the coefficients of a randomized projective transformation.
49// The image transform requires backward transformation coefficient, and the
50// box transform the forward coefficients.
51// Returns the incolor arg to pixProjective.
52int ProjectiveCoeffs(int width, int height, TRand *randomizer, float **im_coeffs,
53 float **box_coeffs);
54
55} // namespace tesseract
56
57#endif // TESSERACT_TRAINING_DEGRADEIMAGE_H_
Image PrepareDistortedPix(const Image pix, bool perspective, bool invert, bool white_noise, bool smooth_noise, bool blur, int box_reduction, TRand *randomizer, std::vector< TBOX > *boxes)
int ProjectiveCoeffs(int width, int height, TRand *randomizer, float **im_coeffs, float **box_coeffs)
void GeneratePerspectiveDistortion(int width, int height, TRand *randomizer, Image *pix, std::vector< TBOX > *boxes)
Image DegradeImage(Image input, int exposure, TRand *randomizer, float *rotation)