tesseract  5.0.0
tesseract::PixelHistogram Class Reference

#include <devanagari_processing.h>

Public Member Functions

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

Detailed Description

Definition at line 33 of file devanagari_processing.h.

Constructor & Destructor Documentation

◆ PixelHistogram()

tesseract::PixelHistogram::PixelHistogram ( )
inline

Definition at line 35 of file devanagari_processing.h.

35  {
36  hist_ = nullptr;
37  length_ = 0;
38  }

◆ ~PixelHistogram()

tesseract::PixelHistogram::~PixelHistogram ( )
inline

Definition at line 40 of file devanagari_processing.h.

40  {
41  Clear();
42  }

Member Function Documentation

◆ Clear()

void tesseract::PixelHistogram::Clear ( )
inline

Definition at line 44 of file devanagari_processing.h.

44  {
45  delete[] hist_;
46  length_ = 0;
47  }

◆ ConstructHorizontalCountHist()

void tesseract::PixelHistogram::ConstructHorizontalCountHist ( Image  pix)

Definition at line 474 of file devanagari_processing.cpp.

474  {
475  Clear();
476  Numa *counts = pixCountPixelsByRow(pix, nullptr);
477  length_ = numaGetCount(counts);
478  hist_ = new int[length_];
479  for (int i = 0; i < length_; ++i) {
480  l_int32 val = 0;
481  numaGetIValue(counts, i, &val);
482  hist_[i] = val;
483  }
484  numaDestroy(&counts);
485 }

◆ ConstructVerticalCountHist()

void tesseract::PixelHistogram::ConstructVerticalCountHist ( Image  pix)

Definition at line 453 of file devanagari_processing.cpp.

453  {
454  Clear();
455  int width = pixGetWidth(pix);
456  int height = pixGetHeight(pix);
457  hist_ = new int[width];
458  length_ = width;
459  int wpl = pixGetWpl(pix);
460  l_uint32 *data = pixGetData(pix);
461  for (int i = 0; i < width; ++i) {
462  hist_[i] = 0;
463  }
464  for (int i = 0; i < height; ++i) {
465  l_uint32 *line = data + i * wpl;
466  for (int j = 0; j < width; ++j) {
467  if (GET_DATA_BIT(line, j)) {
468  ++(hist_[j]);
469  }
470  }
471  }
472 }

◆ GetHistogramMaximum()

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

Definition at line 439 of file devanagari_processing.cpp.

439  {
440  int best_value = 0;
441  for (int i = 0; i < length_; ++i) {
442  if (hist_[i] > hist_[best_value]) {
443  best_value = i;
444  }
445  }
446  if (count) {
447  *count = hist_[best_value];
448  }
449  return best_value;
450 }

◆ hist()

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

Definition at line 49 of file devanagari_processing.h.

49  {
50  return hist_;
51  }

◆ length()

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

Definition at line 53 of file devanagari_processing.h.

53  {
54  return length_;
55  }

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