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
00071 virtual bool HasThresholdToPix() const;
00072
00074 bool IsColor() const {
00075 return image_bytespp_ >= 3;
00076 }
00077
00080 virtual void ThresholdToIMAGE(IMAGE* image);
00081
00082 #ifdef HAVE_LIBLEPT
00083
00084
00085
00086
00087
00088
00089
00090
00091 void SetImage(const Pix* pix);
00092
00096 virtual void ThresholdToPix(Pix** pix);
00097
00103 Pix* GetPixRect();
00104 #endif
00105
00106 protected:
00107
00108
00109
00111 virtual void Init();
00112
00114 bool IsFullImage() const {
00115 return rect_left_ == 0 && rect_top_ == 0 &&
00116 rect_width_ == image_width_ && rect_height_ == image_height_;
00117 }
00118
00121 void OtsuThresholdRectToIMAGE(const unsigned char* imagedata,
00122 int bytes_per_pixel, int bytes_per_line,
00123 IMAGE* image) const;
00124
00127 void ThresholdRectToIMAGE(const unsigned char* imagedata,
00128 int bytes_per_pixel, int bytes_per_line,
00129 const int* thresholds, const int* hi_values,
00130 IMAGE* image) const;
00131
00134 void CopyBinaryRectRawToIMAGE(IMAGE* image) const;
00135
00136 #ifdef HAVE_LIBLEPT
00137
00138
00139 void OtsuThresholdRectToPix(const unsigned char* imagedata,
00140 int bytes_per_pixel, int bytes_per_line,
00141 Pix** pix) const;
00142
00145 void ThresholdRectToPix(const unsigned char* imagedata,
00146 int bytes_per_pixel, int bytes_per_line,
00147 const int* thresholds, const int* hi_values,
00148 Pix** pix) const;
00149
00151 void RawRectToPix(Pix** pix) const;
00152
00154 void CopyBinaryRectPixToIMAGE(IMAGE* image) const;
00155 #endif
00156
00157 protected:
00158 #ifdef HAVE_LIBLEPT
00159
00160
00161 Pix* pix_;
00162 #endif
00163
00164 const unsigned char* image_data_;
00165
00166 int image_width_;
00167 int image_height_;
00168 int image_bytespp_;
00169 int image_bytespl_;
00170
00171 int rect_left_;
00172 int rect_top_;
00173 int rect_width_;
00174 int rect_height_;
00175 };
00176
00177 }
00178
00179 #endif // TESSERACT_CCMAIN_THRESHOLDER_H__
00180