private string HistoGramValues(string _imageName)
{
// Get your image in a bitmap; this is how to get it from a picturebox
Bitmap bmOriginal = new Bitmap("D:\\inetpub\\webs\\francescobelloniit\\universita\\eimmagini\\images\\" + _imageName);
// Get your image in greyscale
Bitmap bm = MakeGrayscale3(bmOriginal);
int h = bm.Height;
int l = bm.Width;
CheckValueTest = "immagine alta:" + h + ", larga: " + l + "("+h+"x"+l+" = "+(h*l).ToString()+")";
// Store the histogram in a dictionary (grigio | valore di grigio)
Dictionary<int, int> histo = new Dictionary<int, int>();
for (int x = 0; x < bm.Width; x++)
{
for (int y = 0; y < bm.Height; y++)
{
// Get pixel color
Color c = bm.GetPixel(x, y);
int grey = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
// If it exists in our 'histogram' increment the corresponding value, or add new
if (histo.ContainsKey(grey))
histo[grey] = histo[grey] + 1;
else
histo.Add(grey, 1);
}
}
int nPx=0;
// This outputs the histogram in an output window
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 256; i++)
{
if (histo.ContainsKey(i))
{
sb.Append("{ x: '" + i + "', y: " + histo[i] + " }," + "\r\n");
nPx+=histo[i];
}
}
CheckValueTest += "--> ho contato " + nPx + "px";
string temp = sb.ToString();
temp=RemoveLast(temp,",");
showValues += temp.Replace("\r\n","<br />");
return getHistogramScript(temp);
}