c# - How to 'normalize' a grayscale image? -
my math bit rusty. i'm trying equalize histogram of 2d array represents grayscale values in range 0-255 (values may not whole numbers because of how computed).
i found this article on wikipedia, don't quite understand formulas present.
ni, n , l can compute, i'm not quite sure how implement cdf function. might this function of use?
here's i've got far:
static double[,] normalize(double[,] mat) { int width = mat.getlength(0); int height = mat.getlength(1); int npixels = width*height; double sum = 0; double max = double.minvalue; double min = double.maxvalue; var graylevels = new dictionary<double, int>(); foreach (var g in mat) { sum += g; if (g > max) max = g; if (g < min) min = g; if (!graylevels.containskey(g)) graylevels[g] = 0; ++graylevels[g]; } double avg = sum/npixels; double range = max - min; var = new double[width,height]; // how normalize? return i; }
found might find useful
http://sonabstudios.blogspot.in/2011/01/histogram-equalization-algorithm.html
hope helps
Comments
Post a Comment