Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
ColorFilterHistogram Class Reference

Class that generates a histogram according to the current filter. More...

#include <ColorFilterHistogram.h>

Collaboration diagram for ColorFilterHistogram:
Collaboration graph

Public Member Functions

 ColorFilterHistogram ()
 Single constructor.
 
int binFromPixel (const ColorFilter &filter, ColorFilterMode colorFilterMode, const QColor &pixel, const QRgb &rgbBackground) const
 Compute histogram bin number from pixel according to filter.
 
void generate (const ColorFilter &filter, double histogramBins[], ColorFilterMode colorFilterMode, const QImage &image, int &maxBinCount) const
 Generate the histogram.
 
int valueFromBin (const ColorFilter &filter, ColorFilterMode colorFilterMode, int bin)
 Inverse of binFromPixel.
 

Static Public Member Functions

static int HISTOGRAM_BINS ()
 Number of histogram bins.
 

Detailed Description

Class that generates a histogram according to the current filter.

Definition at line 17 of file ColorFilterHistogram.h.

Constructor & Destructor Documentation

◆ ColorFilterHistogram()

ColorFilterHistogram::ColorFilterHistogram ( )

Single constructor.

Definition at line 13 of file ColorFilterHistogram.cpp.

14{
15}

Member Function Documentation

◆ binFromPixel()

int ColorFilterHistogram::binFromPixel ( const ColorFilter & filter,
ColorFilterMode colorFilterMode,
const QColor & pixel,
const QRgb & rgbBackground ) const

Compute histogram bin number from pixel according to filter.

Definition at line 17 of file ColorFilterHistogram.cpp.

21{
22 // Instead of mapping from s=0 through 1 to bin=0 through HISTOGRAM_BINS-1, we
23 // map it to bin=1 through HISTOGRAM_BINS-2 so first and last bin are zero. The
24 // result is a peak at the start or end is complete and easier to read
25 double s = filter.pixelToZeroToOneOrMinusOne (colorFilterMode,
26 pixel,
28 ENGAUGE_ASSERT (s <= 1.0);
29
30 int bin = -1;
31
32 if (s >= 0) {
33
34 bin = qFloor (FIRST_NON_EMPTY_BIN_AT_START () + s * (LAST_NON_EMPTY_BIN_AT_END () - FIRST_NON_EMPTY_BIN_AT_START ()));
35
36 }
37
38 return bin;
39}
const int INNER_RADIUS_MIN
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
double pixelToZeroToOneOrMinusOne(ColorFilterMode colorFilterMode, const QColor &pixel, QRgb rgbBackground) const
Return pixel converted according to the current filter parameter, normalized to zero to one.

◆ generate()

void ColorFilterHistogram::generate ( const ColorFilter & filter,
double histogramBins[],
ColorFilterMode colorFilterMode,
const QImage & image,
int & maxBinCount ) const

Generate the histogram.

The resolution is coarse since

  1. finer resolution is not needed
  2. this smooths out the curve

Definition at line 41 of file ColorFilterHistogram.cpp.

46{
47 // Initialize histogram bins
48 int bin;
49 for (bin = 0; bin < HISTOGRAM_BINS (); bin++) {
50 histogramBins [bin] = 0;
51 }
52
53 QRgb rgbBackground = filter.marginColor(&image);
54
55 // Populate histogram bins
56 maxBinCount = 0;
57 for (int x = 0; x < image.width(); x++) {
58 for (int y = 0; y < image.height(); y++) {
59
60 QColor pixel (image.pixel (x, y));
61 int bin = binFromPixel (filter,
62 colorFilterMode,
63 pixel,
65 if (bin >= 0) {
66
67 ENGAUGE_ASSERT ((FIRST_NON_EMPTY_BIN_AT_START () <= bin) &&
68 (LAST_NON_EMPTY_BIN_AT_END () >= bin));
69 ++(histogramBins [bin]);
70
73 }
74 }
75 }
76 }
77}
static int HISTOGRAM_BINS()
Number of histogram bins.
int binFromPixel(const ColorFilter &filter, ColorFilterMode colorFilterMode, const QColor &pixel, const QRgb &rgbBackground) const
Compute histogram bin number from pixel according to filter.
QRgb marginColor(const QImage *image) const
Identify the margin color of the image, which is defined as the most common color in the four margins...

◆ HISTOGRAM_BINS()

static int ColorFilterHistogram::HISTOGRAM_BINS ( )
inlinestatic

Number of histogram bins.

Definition at line 39 of file ColorFilterHistogram.h.

39{ return 100; }

◆ valueFromBin()

int ColorFilterHistogram::valueFromBin ( const ColorFilter & filter,
ColorFilterMode colorFilterMode,
int bin )

Inverse of binFromPixel.

Definition at line 79 of file ColorFilterHistogram.cpp.

82{
83 // Just do everything in binFromPixel backwards
84 double s = double (bin - FIRST_NON_EMPTY_BIN_AT_START ()) / double (LAST_NON_EMPTY_BIN_AT_END () - FIRST_NON_EMPTY_BIN_AT_START ());
85 s = qMin (qMax (s, 0.0), 1.0);
86
87 return filter.zeroToOneToValue (colorFilterMode,
88 s);
89}
int zeroToOneToValue(ColorFilterMode colorFilterMode, double s) const
Inverse of pixelToZeroToOneOrMinusOne.

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