tesseract  5.0.0-alpha-619-ge9db
tesseract::PixelHistogram Class Reference

#include <devanagari_processing.h>

Public Member Functions

 PixelHistogram ()
 
 ~PixelHistogram ()
 
void Clear ()
 
int * hist () const
 
int length () const
 
void ConstructVerticalCountHist (Pix *pix)
 
void ConstructHorizontalCountHist (Pix *pix)
 
int GetHistogramMaximum (int *count) const
 

Detailed Description

Definition at line 36 of file devanagari_processing.h.

Constructor & Destructor Documentation

◆ PixelHistogram()

tesseract::PixelHistogram::PixelHistogram ( )
inline

Definition at line 38 of file devanagari_processing.h.

38  {
39  hist_ = nullptr;
40  length_ = 0;
41  }

◆ ~PixelHistogram()

tesseract::PixelHistogram::~PixelHistogram ( )
inline

Definition at line 43 of file devanagari_processing.h.

43  {
44  Clear();
45  }

Member Function Documentation

◆ Clear()

void tesseract::PixelHistogram::Clear ( )
inline

Definition at line 47 of file devanagari_processing.h.

47  {
48  delete[] hist_;
49  length_ = 0;
50  }

◆ ConstructHorizontalCountHist()

void tesseract::PixelHistogram::ConstructHorizontalCountHist ( Pix *  pix)

Definition at line 487 of file devanagari_processing.cpp.

487  {
488  Clear();
489  Numa* counts = pixCountPixelsByRow(pix, nullptr);
490  length_ = numaGetCount(counts);
491  hist_ = new int[length_];
492  for (int i = 0; i < length_; ++i) {
493  l_int32 val = 0;
494  numaGetIValue(counts, i, &val);
495  hist_[i] = val;
496  }
497  numaDestroy(&counts);
498 }

◆ ConstructVerticalCountHist()

void tesseract::PixelHistogram::ConstructVerticalCountHist ( Pix *  pix)

Definition at line 469 of file devanagari_processing.cpp.

469  {
470  Clear();
471  int width = pixGetWidth(pix);
472  int height = pixGetHeight(pix);
473  hist_ = new int[width];
474  length_ = width;
475  int wpl = pixGetWpl(pix);
476  l_uint32 *data = pixGetData(pix);
477  for (int i = 0; i < width; ++i)
478  hist_[i] = 0;
479  for (int i = 0; i < height; ++i) {
480  l_uint32 *line = data + i * wpl;
481  for (int j = 0; j < width; ++j)
482  if (GET_DATA_BIT(line, j))
483  ++(hist_[j]);
484  }
485 }

◆ GetHistogramMaximum()

int tesseract::PixelHistogram::GetHistogramMaximum ( int *  count) const

Definition at line 455 of file devanagari_processing.cpp.

455  {
456  int best_value = 0;
457  for (int i = 0; i < length_; ++i) {
458  if (hist_[i] > hist_[best_value]) {
459  best_value = i;
460  }
461  }
462  if (count) {
463  *count = hist_[best_value];
464  }
465  return best_value;
466 }

◆ hist()

int* tesseract::PixelHistogram::hist ( ) const
inline

Definition at line 52 of file devanagari_processing.h.

52 { return hist_; }

◆ length()

int tesseract::PixelHistogram::length ( ) const
inline

Definition at line 54 of file devanagari_processing.h.

54  {
55  return length_;
56  }

The documentation for this class was generated from the following files:
tesseract::PixelHistogram::Clear
void Clear()
Definition: devanagari_processing.h:47
count
int count(LIST var_list)
Definition: oldlist.cpp:79