Closed GoogleCodeExporter closed 9 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
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
Original issue reported on code.google.com by
Nathanae...@gmail.com
on 2 Aug 2012 at 8:24