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