I have a 2d array which contains a binary image, all the values are either set to 0 or 255. An example image is as follows:
I'd like to know what the size of each 'blob' is. A blob being the number connected white pixels.
I tried to implement a distance transform algorithm: (note that the "MatrixData" class is essentially a double[,])
public static MatrixData CalculateDistanceXform(this MatrixData input, int searchDistance)
{
MatrixData output = new MatrixData(input.NumberOfRows,input.NumberOfColumns);
for (int r = 0; r < input.NumberOfRows; r++)
{
for(int c = 0; c < input.NumberOfColumns; c++)
{
//skip black pixels
if (input[r,c]==0) continue;
int steps = 0;
int fxMin = Math.Max(r - searchDistance, 0);
int fxMax = Math.Min(r + searchDistance, input.NumberOfRows);
int fyMin = Math.Max(c - searchDistance, 0);
int fyMax = Math.Min(c + searchDistance, input.NumberOfColumns);
for (int fx = fxMin; fx < fxMax-1; ++fx)
{
for (int fy = fyMin; fy < fyMax-1; ++fy)
{
if(input[fx,fy]==255)
{
int tempStep = ((fx - fxMin) + (fy - fyMin));
if(tempStep > steps) steps = tempStep;
}
}
}
output[r,c] = steps;
}
}
return output.HistEQ();
}
However this didn't give me the result i wanted as my blobs are not uniform in size. Any ideas on how to solve this? I essentially want to find a x and y coordinate that is in the largest blob of the image.