tesseract v5.3.3.20231005
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 480 of file devanagari_processing.cpp.

480 {
481 Clear();
482 Numa *counts = pixCountPixelsByRow(pix, nullptr);
483 length_ = numaGetCount(counts);
484 hist_ = new int[length_];
485 for (int i = 0; i < length_; ++i) {
486 l_int32 val = 0;
487 numaGetIValue(counts, i, &val);
488 hist_[i] = val;
489 }
490 numaDestroy(&counts);
491}

◆ ConstructVerticalCountHist()

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

Definition at line 459 of file devanagari_processing.cpp.

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

◆ GetHistogramMaximum()

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

Definition at line 445 of file devanagari_processing.cpp.

445 {
446 int best_value = 0;
447 for (int i = 0; i < length_; ++i) {
448 if (hist_[i] > hist_[best_value]) {
449 best_value = i;
450 }
451 }
452 if (count) {
453 *count = hist_[best_value];
454 }
455 return best_value;
456}
int * count

◆ 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: