tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
tesseract::ImageThresholder Class Reference

#include <thresholder.h>

Public Member Functions

 ImageThresholder ()
 
virtual ~ImageThresholder ()
 
virtual void Clear ()
 Destroy the Pix if there is one, freeing memory. More...
 
bool IsEmpty () const
 Return true if no image has been set. More...
 
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. More...
 
bool IsBinary () const
 Returns true if the source image is binary. More...
 
int GetScaleFactor () const
 
void SetSourceYResolution (int ppi)
 
int GetSourceYResolution () const
 
int GetScaledYResolution () const
 
void SetEstimatedResolution (int ppi)
 
int GetScaledEstimatedResolution () const
 
void SetImage (const Pix *pix)
 
virtual bool ThresholdToPix (PageSegMode pageseg_mode, Pix **pix)
 Returns false on error. More...
 
virtual Pix * GetPixRectThresholds ()
 
Pix * GetPixRect ()
 
virtual Pix * GetPixRectGrey ()
 

Protected Member Functions

virtual void Init ()
 Common initialization shared between SetImage methods. More...
 
bool IsFullImage () const
 Return true if we are processing the full image. More...
 
void OtsuThresholdRectToPix (Pix *src_pix, Pix **out_pix) const
 
void ThresholdRectToPix (Pix *src_pix, int num_channels, const int *thresholds, const int *hi_values, Pix **pix) const
 

Protected Attributes

Pix * pix_
 
int image_width_
 
int image_height_
 
int pix_channels_
 
int pix_wpl_
 
int scale_
 
int yres_
 
int estimated_res_
 
int rect_left_
 
int rect_top_
 
int rect_width_
 
int rect_height_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ImageThresholder()

tesseract::ImageThresholder::ImageThresholder ( )

◆ ~ImageThresholder()

tesseract::ImageThresholder::~ImageThresholder ( )
virtual

Member Function Documentation

◆ Clear()

void tesseract::ImageThresholder::Clear ( )
virtual

Destroy the Pix if there is one, freeing memory.

◆ GetImageSizes()

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.

◆ GetPixRect()

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.

◆ GetPixRectGrey()

Pix * tesseract::ImageThresholder::GetPixRectGrey ( )
virtual

◆ GetPixRectThresholds()

Pix * tesseract::ImageThresholder::GetPixRectThresholds ( )
virtual

◆ GetScaledEstimatedResolution()

int tesseract::ImageThresholder::GetScaledEstimatedResolution ( ) const
inline

◆ GetScaledYResolution()

int tesseract::ImageThresholder::GetScaledYResolution ( ) const
inline

◆ GetScaleFactor()

int tesseract::ImageThresholder::GetScaleFactor ( ) const
inline

◆ GetSourceYResolution()

int tesseract::ImageThresholder::GetSourceYResolution ( ) const
inline

◆ Init()

void tesseract::ImageThresholder::Init ( )
protectedvirtual

Common initialization shared between SetImage methods.

◆ IsBinary()

bool tesseract::ImageThresholder::IsBinary ( ) const
inline

Returns true if the source image is binary.

◆ IsColor()

bool tesseract::ImageThresholder::IsColor ( ) const
inline

Return true if the source image is color.

◆ IsEmpty()

bool tesseract::ImageThresholder::IsEmpty ( ) const

Return true if no image has been set.

◆ IsFullImage()

bool tesseract::ImageThresholder::IsFullImage ( ) const
inlineprotected

Return true if we are processing the full image.

◆ OtsuThresholdRectToPix()

void tesseract::ImageThresholder::OtsuThresholdRectToPix ( Pix *  src_pix,
Pix **  out_pix 
) const
protected

◆ SetEstimatedResolution()

void tesseract::ImageThresholder::SetEstimatedResolution ( int  ppi)
inline

◆ SetImage() [1/2]

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 all the image data, so it may be deleted immediately after this call. 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.

◆ SetImage() [2/2]

void tesseract::ImageThresholder::SetImage ( const Pix *  pix)

Pix vs raw, which to use? Pix is the preferred input for efficiency, since raw buffers are copied. SetImage for Pix clones its input, so the source pix may be pixDestroyed immediately after, but may not go away until after the Thresholder has finished with it.

◆ SetRectangle()

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.

◆ SetSourceYResolution()

void tesseract::ImageThresholder::SetSourceYResolution ( int  ppi)
inline

◆ ThresholdRectToPix()

void tesseract::ImageThresholder::ThresholdRectToPix ( Pix *  src_pix,
int  num_channels,
const int *  thresholds,
const int *  hi_values,
Pix **  pix 
) const
protected

Threshold the rectangle, taking everything except the src_pix from the class, using thresholds/hi_values to the output pix. NOTE that num_channels is the size of the thresholds and hi_values

◆ ThresholdToPix()

bool tesseract::ImageThresholder::ThresholdToPix ( PageSegMode  pageseg_mode,
Pix **  pix 
)
virtual

Returns false on error.

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. Returns false on error.

Member Data Documentation

◆ estimated_res_

int tesseract::ImageThresholder::estimated_res_
protected

◆ image_height_

int tesseract::ImageThresholder::image_height_
protected

◆ image_width_

int tesseract::ImageThresholder::image_width_
protected

◆ pix_

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.

◆ pix_channels_

int tesseract::ImageThresholder::pix_channels_
protected

◆ pix_wpl_

int tesseract::ImageThresholder::pix_wpl_
protected

◆ rect_height_

int tesseract::ImageThresholder::rect_height_
protected

◆ rect_left_

int tesseract::ImageThresholder::rect_left_
protected

◆ rect_top_

int tesseract::ImageThresholder::rect_top_
protected

◆ rect_width_

int tesseract::ImageThresholder::rect_width_
protected

◆ scale_

int tesseract::ImageThresholder::scale_
protected

◆ yres_

int tesseract::ImageThresholder::yres_
protected

The documentation for this class was generated from the following files: