kadorek / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

HistogramEqualization.Equalize should be made virtual #313

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Describe the feature you are interested and which may bring benefit to the
project ...

Currently, HistogramEqualization implements a very poor stretching method, and 
does not permit truncation of low-frequency values. 

Simply making the Equalize method overridable would permit this to be corrected 
by users, and reused for a variety of histogram-based approaches (white balance 
correction ,etc). 

Change private byte Equalize to protected virtual.

http://code.google.com/p/aforge/source/browse/trunk/Sources/Imaging/Filters/Colo
r%20Filters/HistogramEqualization.cs

Provide any references/links to publications/algorithms/etc. which could
help in development ...

Original issue reported on code.google.com by Nathanae...@gmail.com on 2 Aug 2012 at 8:24

GoogleCodeExporter commented 8 years ago
I also suggest a different implementation - the current one does not support 
adjustable range truncation, which is the primary reason the results are so 
poor. 

 private double truncateLow = 0.0005f;
        private double truncateHigh = 0.0005f;

        // Histogram 
        private byte[] Equalize(int[] histogram, long numPixel) {

            //Low and high indexes to stretch
            int low = 0; int high = 255;

            double totalPixels = (double)numPixel;

            for (int i = 0; i < 256; i++) {
                if ((double)histogram[i] / numPixel > truncateLow) {
                    low = i;
                    break;
                }
            }
            //Find high
            for (int i = 255; i >= 0; i--) {
                if ((double)histogram[i] / totalPixels > truncateHigh) {
                    high = i;
                    break;
                }
            }

            //Calculate scale factor
            double scale = 255.0 / (double)(high - low);

            //Create the new, scaled mapping
            byte[] equalizedHistogram = new byte[256];
            for (int i = 0; i < 256; i++) {
                equalizedHistogram[i] = (byte)Math.Max(0,Math.Min(255,Math.Round(((double)i * scale) - low )));
            }

            return equalizedHistogram;
        }
    }

Original comment by Nathanae...@gmail.com on 6 Aug 2012 at 3:08

GoogleCodeExporter commented 8 years ago
The code you've suggested has nothing in common to Histogram Equalization. It 
is just bit of improovement for Contrast Stretch:
http://code.google.com/p/aforge/source/browse/trunk/Sources/Imaging/Filters/Colo
r%20Filters/ContrastStretch.cs

Original comment by andrew.k...@gmail.com on 18 Jun 2013 at 4:54