7 #include "ColorFilter.h"
8 #include "ColorFilterHistogram.h"
9 #include "EngaugeAssert.h"
18 ColorFilterMode colorFilterMode,
20 const QRgb &rgbBackground)
const
28 ENGAUGE_ASSERT (s <= 1.0);
34 bin = qFloor (FIRST_NON_EMPTY_BIN_AT_START () + s * (LAST_NON_EMPTY_BIN_AT_END () - FIRST_NON_EMPTY_BIN_AT_START ()));
42 double histogramBins [],
43 ColorFilterMode colorFilterMode,
45 int &maxBinCount)
const
50 histogramBins [bin] = 0;
57 for (
int x = 0; x < image.width(); x++) {
58 for (
int y = 0; y < image.height(); y++) {
60 QColor pixel (image.pixel (x, y));
67 ENGAUGE_ASSERT ((FIRST_NON_EMPTY_BIN_AT_START () <= bin) &&
68 (LAST_NON_EMPTY_BIN_AT_END () >= bin));
69 ++(histogramBins [bin]);
71 if (histogramBins [bin] > maxBinCount) {
72 maxBinCount = qFloor (histogramBins [bin]);
80 ColorFilterMode colorFilterMode,
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);
void generate(const ColorFilter &filter, double histogramBins[], ColorFilterMode colorFilterMode, const QImage &image, int &maxBinCount) const
Generate the histogram.
double pixelToZeroToOneOrMinusOne(ColorFilterMode colorFilterMode, const QColor &pixel, QRgb rgbBackground) const
Return pixel converted according to the current filter parameter, normalized to zero to one...
Class for filtering image to remove unimportant information.
int zeroToOneToValue(ColorFilterMode colorFilterMode, double s) const
Inverse of pixelToZeroToOneOrMinusOne.
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...
int binFromPixel(const ColorFilter &filter, ColorFilterMode colorFilterMode, const QColor &pixel, const QRgb &rgbBackground) const
Compute histogram bin number from pixel according to filter.
int valueFromBin(const ColorFilter &filter, ColorFilterMode colorFilterMode, int bin)
Inverse of binFromPixel.
ColorFilterHistogram()
Single constructor.
static int HISTOGRAM_BINS()
Number of histogram bins.