Hi, first off the image dilate and erode methods use a 3x3 grid of pixels this will effect your results, but I assume this is deliberate.
I'd start off using a 3x3 white image to start with, and comment the erode, dilate, threshold and re-size operations. That way you have baseline to check the rest of your code.
ImageBox doesn't make much sense to me: you'd be better off just using
binary
.
You don't have comparison anywhere, I'd expect you to compare the current pixel in your loop with a white one, or compare the brightness value with 255.
[edit]
the contents of loop is wrong for counting the white pixels, you have two preoblems:
binary.Data[i, j, 0] = 255;
then
byte white = binary.Data[i, j, 0];
Gets the value of the pixel, which you've just set to white (255).
I think you need something more like:
int count = 0;
for (int i = 0; i < binary.Rows; i++)
{
for (int j = 0; j < binary.Cols; j++)
{
if(binary.Data[i, j, 0] == 255)
count++;
lblWhite.Text = string.Format("{0} white pixels", count);
}
}
One thing I've found is that looping the pixels in any reasonably sized image is slow, but you should only optimise one your basic algorithm is working.