I am trying to get the max intensity value and min intensity from an image called btm
to get the average from the "max, min", then use this average as a threshold to convert image to binary image.
So I used histogram class from aforge library which takes an int array, so I am trying to convert my image btm
to the array but the function ImageToByteArray
that I used to convert image return array from byte data type.
System.Drawing.Image img = (System.Drawing.Image)btm;
byte[] imgarr = ImageToByteArray(img);
Histogram h = new Histogram(imgarr);
int Maxval= h.max();
int Minval= h.min();
.
public static byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
using (var ms = new MemoryStream())
{
imageIn.Save(ms, imageIn.RawFormat);
return ms.ToArray();
}
}