00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020 #ifndef TESSERACT_CCMAIN_THRESHOLDER_H__
00021 #define TESSERACT_CCMAIN_THRESHOLDER_H__
00022
00023 class IMAGE;
00024 struct Pix;
00025
00026 namespace tesseract {
00027
00034 class ImageThresholder {
00035 public:
00036 ImageThresholder();
00037 virtual ~ImageThresholder();
00038
00040 virtual void Clear();
00041
00043 bool IsEmpty() const;
00044
00055 void SetImage(const unsigned char* imagedata, int width, int height,
00056 int bytes_per_pixel, int bytes_per_line);
00057
00060 void SetRectangle(int left, int top, int width, int height);
00061
00066 virtual void GetImageSizes(int* left, int* top, int* width, int* height,
00067 int* imagewidth, int* imageheight);
00068
00070 bool IsColor() const {
00071 return image_bytespp_ >= 3;
00072 }
00073
00075 bool IsBinary() const {
00076 return image_bytespp_ == 0;
00077 }
00078
00079 int GetScaleFactor() const {
00080 return scale_;
00081 }
00082
00083
00084
00085
00086 void SetSourceYResolution(int ppi) {
00087 yres_ = ppi;
00088 estimated_res_ = ppi;
00089 }
00090 int GetSourceYResolution() const {
00091 return yres_;
00092 }
00093 int GetScaledYResolution() const {
00094 return scale_ * yres_;
00095 }
00096
00097
00098
00099
00100
00101 void SetEstimatedResolution(int ppi) {
00102 estimated_res_ = ppi;
00103 }
00104
00105
00106 int GetScaledEstimatedResolution() const {
00107 return scale_ * estimated_res_;
00108 }
00109
00118 void SetImage(const Pix* pix);
00119
00123 virtual void ThresholdToPix(Pix** pix);
00124
00130 Pix* GetPixRect();
00131
00137 Pix* GetPixRectGrey();
00138
00139 protected:
00140
00141
00142
00144 virtual void Init();
00145
00147 bool IsFullImage() const {
00148 return rect_left_ == 0 && rect_top_ == 0 &&
00149 rect_width_ == image_width_ && rect_height_ == image_height_;
00150 }
00151
00154 void OtsuThresholdRectToPix(const unsigned char* imagedata,
00155 int bytes_per_pixel, int bytes_per_line,
00156 Pix** pix) const;
00157
00160 void ThresholdRectToPix(const unsigned char* imagedata,
00161 int bytes_per_pixel, int bytes_per_line,
00162 const int* thresholds, const int* hi_values,
00163 Pix** pix) const;
00164
00166 void RawRectToPix(Pix** pix) const;
00167
00168 protected:
00171 Pix* pix_;
00173 const unsigned char* image_data_;
00174
00175 int image_width_;
00176 int image_height_;
00177 int image_bytespp_;
00178 int image_bytespl_;
00179
00180 int scale_;
00181 int yres_;
00182 int estimated_res_;
00183 int rect_left_;
00184 int rect_top_;
00185 int rect_width_;
00186 int rect_height_;
00187 };
00188
00189 }
00190
00191 #endif // TESSERACT_CCMAIN_THRESHOLDER_H__