Tesseract 3.01
|
#include <thresholder.h>
Public Member Functions | |
ImageThresholder () | |
virtual | ~ImageThresholder () |
virtual void | Clear () |
Destroy the Pix if there is one, freeing memory. | |
bool | IsEmpty () const |
Return true if no image has been set. | |
void | SetImage (const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line) |
void | SetRectangle (int left, int top, int width, int height) |
virtual void | GetImageSizes (int *left, int *top, int *width, int *height, int *imagewidth, int *imageheight) |
bool | IsColor () const |
Return true if the source image is color. | |
bool | IsBinary () const |
Returns true if the source image is binary. | |
int | GetScaleFactor () const |
int | GetSourceYResolution () const |
int | GetScaledYResolution () const |
void | SetImage (const Pix *pix) |
virtual void | ThresholdToPix (Pix **pix) |
Pix * | GetPixRect () |
Pix * | GetPixRectGrey () |
Protected Member Functions | |
virtual void | Init () |
Common initialization shared between SetImage methods. | |
bool | IsFullImage () const |
Return true if we are processing the full image. | |
void | OtsuThresholdRectToPix (const unsigned char *imagedata, int bytes_per_pixel, int bytes_per_line, Pix **pix) const |
void | ThresholdRectToPix (const unsigned char *imagedata, int bytes_per_pixel, int bytes_per_line, const int *thresholds, const int *hi_values, Pix **pix) const |
void | RawRectToPix (Pix **pix) const |
Copy the raw image rectangle, taking all data from the class, to the Pix. | |
Protected Attributes | |
Pix * | pix_ |
const unsigned char * | image_data_ |
Exactly one of pix_ and image_data_ is not NULL. | |
int | image_width_ |
int | image_height_ |
int | image_bytespp_ |
int | image_bytespl_ |
int | scale_ |
int | yres_ |
int | rect_left_ |
int | rect_top_ |
int | rect_width_ |
int | rect_height_ |
Base class for all tesseract image thresholding classes. Specific classes can add new thresholding methods by overriding ThresholdToPix. Each instance deals with a single image, but the design is intended to be useful for multiple calls to SetRectangle and ThresholdTo* if desired.
tesseract::ImageThresholder::ImageThresholder | ( | ) |
tesseract::ImageThresholder::~ImageThresholder | ( | ) | [virtual] |
void tesseract::ImageThresholder::Clear | ( | ) | [virtual] |
Destroy the Pix if there is one, freeing memory.
void tesseract::ImageThresholder::GetImageSizes | ( | int * | left, |
int * | top, | ||
int * | width, | ||
int * | height, | ||
int * | imagewidth, | ||
int * | imageheight | ||
) | [virtual] |
Get enough parameters to be able to rebuild bounding boxes in the original image (not just within the rectangle). Left and top are enough with top-down coordinates, but the height of the rectangle and the image are needed for bottom-up.
Pix * tesseract::ImageThresholder::GetPixRect | ( | ) |
Get a clone/copy of the source image rectangle. The returned Pix must be pixDestroyed. This function will be used in the future by the page layout analysis, and the layout analysis that uses it will only be available with Leptonica, so there is no raw equivalent.
Pix * tesseract::ImageThresholder::GetPixRectGrey | ( | ) |
Get a clone/copy of the source image rectangle, reduced to greyscale. The returned Pix must be pixDestroyed. This function will be used in the future by the page layout analysis, and the layout analysis that uses it will only be available with Leptonica, so there is no raw equivalent.
int tesseract::ImageThresholder::GetScaledYResolution | ( | ) | const [inline] |
int tesseract::ImageThresholder::GetScaleFactor | ( | ) | const [inline] |
int tesseract::ImageThresholder::GetSourceYResolution | ( | ) | const [inline] |
void tesseract::ImageThresholder::Init | ( | ) | [protected, virtual] |
Common initialization shared between SetImage methods.
bool tesseract::ImageThresholder::IsBinary | ( | ) | const [inline] |
Returns true if the source image is binary.
bool tesseract::ImageThresholder::IsColor | ( | ) | const [inline] |
Return true if the source image is color.
bool tesseract::ImageThresholder::IsEmpty | ( | ) | const |
Return true if no image has been set.
bool tesseract::ImageThresholder::IsFullImage | ( | ) | const [inline, protected] |
Return true if we are processing the full image.
void tesseract::ImageThresholder::OtsuThresholdRectToPix | ( | const unsigned char * | imagedata, |
int | bytes_per_pixel, | ||
int | bytes_per_line, | ||
Pix ** | pix | ||
) | const [protected] |
Otsu threshold the rectangle, taking everything except the image buffer pointer from the class, to the output Pix.
void tesseract::ImageThresholder::RawRectToPix | ( | Pix ** | pix | ) | const [protected] |
Copy the raw image rectangle, taking all data from the class, to the Pix.
void tesseract::ImageThresholder::SetImage | ( | const unsigned char * | imagedata, |
int | width, | ||
int | height, | ||
int | bytes_per_pixel, | ||
int | bytes_per_line | ||
) |
SetImage makes a copy of only the metadata, not the underlying image buffer. It promises to treat the source as read-only in either case, but in return assumes that the Pix or image buffer remain valid throughout the life of the ImageThresholder. Greyscale of 8 and color of 24 or 32 bits per pixel may be given. Palette color images will not work properly and must be converted to 24 bit. Binary images of 1 bit per pixel may also be given but they must be byte packed with the MSB of the first byte being the first pixel, and a one pixel is WHITE. For binary images set bytes_per_pixel=0.
void tesseract::ImageThresholder::SetImage | ( | const Pix * | pix | ) |
Pix vs raw, which to use? Implementations should provide the ability to source and target Pix where possible. A future version of Tesseract may choose to use Pix as its internal representation and discard IMAGE altogether. Because of that, an implementation that sources and targets Pix may end up with less copies than an implementation that does not. NOTE: Opposite to SetImage for raw images, SetImage for Pix clones its input, so the source pix may be pixDestroyed immediately after.
void tesseract::ImageThresholder::SetRectangle | ( | int | left, |
int | top, | ||
int | width, | ||
int | height | ||
) |
Store the coordinates of the rectangle to process for later use. Doesn't actually do any thresholding.
void tesseract::ImageThresholder::ThresholdRectToPix | ( | const unsigned char * | imagedata, |
int | bytes_per_pixel, | ||
int | bytes_per_line, | ||
const int * | thresholds, | ||
const int * | hi_values, | ||
Pix ** | pix | ||
) | const [protected] |
Threshold the rectangle, taking everything except the image buffer pointer from the class, using thresholds/hi_values to the output IMAGE.
void tesseract::ImageThresholder::ThresholdToPix | ( | Pix ** | pix | ) | [virtual] |
Threshold the source image as efficiently as possible to the output Pix. Creates a Pix and sets pix to point to the resulting pointer. Caller must use pixDestroy to free the created Pix.
int tesseract::ImageThresholder::image_bytespl_ [protected] |
int tesseract::ImageThresholder::image_bytespp_ [protected] |
const unsigned char* tesseract::ImageThresholder::image_data_ [protected] |
Exactly one of pix_ and image_data_ is not NULL.
int tesseract::ImageThresholder::image_height_ [protected] |
int tesseract::ImageThresholder::image_width_ [protected] |
Pix* tesseract::ImageThresholder::pix_ [protected] |
Clone or other copy of the source Pix. The pix will always be PixDestroy()ed on destruction of the class.
int tesseract::ImageThresholder::rect_height_ [protected] |
int tesseract::ImageThresholder::rect_left_ [protected] |
int tesseract::ImageThresholder::rect_top_ [protected] |
int tesseract::ImageThresholder::rect_width_ [protected] |
int tesseract::ImageThresholder::scale_ [protected] |
int tesseract::ImageThresholder::yres_ [protected] |