Tesseract 3.01
|
00001 00002 // File: thresholder.h 00003 // Description: Base API for thresolding images in tesseract. 00004 // Author: Ray Smith 00005 // Created: Mon May 12 11:00:15 PDT 2008 00006 // 00007 // (C) Copyright 2008, Google Inc. 00008 // Licensed under the Apache License, Version 2.0 (the "License"); 00009 // you may not use this file except in compliance with the License. 00010 // You may obtain a copy of the License at 00011 // http://www.apache.org/licenses/LICENSE-2.0 00012 // Unless required by applicable law or agreed to in writing, software 00013 // distributed under the License is distributed on an "AS IS" BASIS, 00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 // See the License for the specific language governing permissions and 00016 // limitations under the License. 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 int GetSourceYResolution() const { 00083 return yres_; 00084 } 00085 int GetScaledYResolution() const { 00086 return scale_ * yres_; 00087 } 00088 00097 void SetImage(const Pix* pix); 00098 00102 virtual void ThresholdToPix(Pix** pix); 00103 00109 Pix* GetPixRect(); 00110 00116 Pix* GetPixRectGrey(); 00117 00118 protected: 00119 // ---------------------------------------------------------------------- 00120 // Utility functions that may be useful components for other thresholders. 00121 00123 virtual void Init(); 00124 00126 bool IsFullImage() const { 00127 return rect_left_ == 0 && rect_top_ == 0 && 00128 rect_width_ == image_width_ && rect_height_ == image_height_; 00129 } 00130 00133 void OtsuThresholdRectToPix(const unsigned char* imagedata, 00134 int bytes_per_pixel, int bytes_per_line, 00135 Pix** pix) const; 00136 00139 void ThresholdRectToPix(const unsigned char* imagedata, 00140 int bytes_per_pixel, int bytes_per_line, 00141 const int* thresholds, const int* hi_values, 00142 Pix** pix) const; 00143 00145 void RawRectToPix(Pix** pix) const; 00146 00147 protected: 00150 Pix* pix_; 00152 const unsigned char* image_data_; //< Raw source image. 00153 00154 int image_width_; //< Width of source image/pix. 00155 int image_height_; //< Height of source image/pix. 00156 int image_bytespp_; //< Bytes per pixel of source image/pix. 00157 int image_bytespl_; //< Bytes per line of source image/pix. 00158 // Limits of image rectangle to be processed. 00159 int scale_; //< Scale factor from original image. 00160 int yres_; //< y pixels/inch in source image 00161 int rect_left_; 00162 int rect_top_; 00163 int rect_width_; 00164 int rect_height_; 00165 }; 00166 00167 } // namespace tesseract. 00168 00169 #endif // TESSERACT_CCMAIN_THRESHOLDER_H__ 00170