Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
thresholder.h
Go to the documentation of this file.
1 
2 // File: thresholder.h
3 // Description: Base API for thresolding images in tesseract.
4 // Author: Ray Smith
5 // Created: Mon May 12 11:00:15 PDT 2008
6 //
7 // (C) Copyright 2008, 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 //
19 
20 #ifndef TESSERACT_CCMAIN_THRESHOLDER_H__
21 #define TESSERACT_CCMAIN_THRESHOLDER_H__
22 
23 class IMAGE;
24 struct Pix;
25 
26 namespace tesseract {
27 
35  public:
37  virtual ~ImageThresholder();
38 
40  virtual void Clear();
41 
43  bool IsEmpty() const;
44 
55  void SetImage(const unsigned char* imagedata, int width, int height,
56  int bytes_per_pixel, int bytes_per_line);
57 
60  void SetRectangle(int left, int top, int width, int height);
61 
66  virtual void GetImageSizes(int* left, int* top, int* width, int* height,
67  int* imagewidth, int* imageheight);
68 
70  bool IsColor() const {
71  return image_bytespp_ >= 3;
72  }
73 
75  bool IsBinary() const {
76  return image_bytespp_ == 0;
77  }
78 
79  int GetScaleFactor() const {
80  return scale_;
81  }
82 
83  // Set the resolution of the source image in pixels per inch.
84  // This should be called right after SetImage(), and will let us return
85  // appropriate font sizes for the text.
86  void SetSourceYResolution(int ppi) {
87  yres_ = ppi;
88  estimated_res_ = ppi;
89  }
90  int GetSourceYResolution() const {
91  return yres_;
92  }
93  int GetScaledYResolution() const {
94  return scale_ * yres_;
95  }
96  // Set the resolution of the source image in pixels per inch, as estimated
97  // by the thresholder from the text size found during thresholding.
98  // This value will be used to set internal size thresholds during recognition
99  // and will not influence the output "point size." The default value is
100  // the same as the source resolution. (yres_)
101  void SetEstimatedResolution(int ppi) {
102  estimated_res_ = ppi;
103  }
104  // Returns the estimated resolution, including any active scaling.
105  // This value will be used to set internal size thresholds during recognition.
107  return scale_ * estimated_res_;
108  }
109 
118  void SetImage(const Pix* pix);
119 
123  virtual void ThresholdToPix(Pix** pix);
124 
130  Pix* GetPixRect();
131 
137  Pix* GetPixRectGrey();
138 
139  protected:
140  // ----------------------------------------------------------------------
141  // Utility functions that may be useful components for other thresholders.
142 
144  virtual void Init();
145 
147  bool IsFullImage() const {
148  return rect_left_ == 0 && rect_top_ == 0 &&
150  }
151 
154  void OtsuThresholdRectToPix(const unsigned char* imagedata,
155  int bytes_per_pixel, int bytes_per_line,
156  Pix** pix) const;
157 
160  void ThresholdRectToPix(const unsigned char* imagedata,
161  int bytes_per_pixel, int bytes_per_line,
162  const int* thresholds, const int* hi_values,
163  Pix** pix) const;
164 
166  void RawRectToPix(Pix** pix) const;
167 
168  protected:
171  Pix* pix_;
173  const unsigned char* image_data_; //< Raw source image.
174 
175  int image_width_; //< Width of source image/pix.
176  int image_height_; //< Height of source image/pix.
177  int image_bytespp_; //< Bytes per pixel of source image/pix.
178  int image_bytespl_; //< Bytes per line of source image/pix.
179  // Limits of image rectangle to be processed.
180  int scale_; //< Scale factor from original image.
181  int yres_; //< y pixels/inch in source image.
182  int estimated_res_; //< Resolution estimate from text size.
187 };
188 
189 } // namespace tesseract.
190 
191 #endif // TESSERACT_CCMAIN_THRESHOLDER_H__