image histogram calculation function
[Algorithm description]
The image histogram describes the number of pixels in the image that have the same grayscale level, which is the function of the image grayscale. In a planar coordinate system, if the gray level (0-255) is represented by a horizontal axis, the ordinate represents the number of pixels in that grayscale level. The formula is expressed as follows:
Where hi represents the distribution function of the grayscale histogram, I represents the grayscale level, NI represents the number of pixels corresponding to the gray level I (here take 8-bit grayscale).
Fig.1 histogram diagram
In Figure Fig.1, the left describes the entire image pixel gray level, the upper right of the table, the second line describes the first row of the number of gray-level pixels, based on this table to draw a histogram as shown in the bottom right image of Fig.1.
[function Code]
///
Get the array of Histrgram.
///
The source image.
///
public static int[] Gethistogramarray (writeablebitmap src)////34 image histogram calculation
{
if (src! = null)
{
int[] histogram = new int[256];
int gray = 0;
byte[] temp = src. Pixelbuffer.toarray ();
for (int i = 0; i < temp. Length; i + = 4)
{
Gray = (int) (Temp[i] * 0.114 + temp[i + 1] * 0.587 + temp[i + 2] * 0.299);
histogram[gray]++;
}
return histogram;
}
Else
{
return null;
}
}
}
}
Demo Download: http://www.zealfilter.com/forum.php?mod=viewthread&tid=20&extra=page%3D2