I am quite new to image processing and I am looking for a solution to obtain the maximum pixel value of a grayscale image. I am using the Aforge.Net library and I tried using the ImageStatistics class to obtain the maximum pixel value of the grayscale image. I just need to make sure if I am on the correct path. Can someone advise me on the following please?
ImageStatistics stat = new ImageStatistics(bmpSource);
Histogram hist = stat.Gray;
int maxPixelVal = hist.Max;
int minPixelVal = hist.Min;
In this snippet I am getting the maximum value using the GrayChannel. I need to make sure whether this would give me the highest pixel value of the whole image or just the gray channel
Thanks in advance
http://www.aforgenet.com/framework/docs/html/937b609f-8d95-662f-c4ac-55eebc44a1cf.htm
ImageStatistics.Gray Property
Histogram of gray channel. Remarks:The property is valid only for grayscale images (see IsGrayscale property).
http://www.aforgenet.com/framework/docs/html/61212d57-52ee-9935-2364-b3a34a2213d0.htm
Histogram.Max Property
The property allows to retrieve maximum value of the histogram with non zero hits count.
So, it looks like this would give you what you want.
One thing to consider is the granularity / resolution of the histogram. Sometimes histograms have a number of bins (values) smaller than the number of possible shades in the colour channel it is representing.
Each bin therefore represents a range of shades / pixel values from the source image, and will give you the count of the number of pixels (or the fraction of the total image) in this range.
If this is the case, you will not be able to get the absolute maximum pixel value from the histogram, only the range in which the maximum pixel fell.
Here however the number of bins looks to be 1:1 with the number of possible shades in the colour channel so your approach should work.