Hi,
I have a problem. I have this image with various regions detected and coloured differntly. What I now need to do is, to find the mathematical center of each of these regions.
I have the code for this.
int labelnew = 2,centerx,centery;
List<Point> l = new List<Point>();
Point p1 = new Point();
Point p2 = new Point();
while (labelnew < label)
{
for (i = 1; i < bd.Height; i++)
{
for (j = 1; j < bd.Width; j++)
{
if (I[j, i] == labelnew)
{
l.Add(p1);
}
}
}
l.Sort();
p1 = l.ElementAt(0);
p2 = l.ElementAt(l.Count - 1);
centerx = (p1.X + p2.X) / 2;
centery = (p1.Y + p2.Y) / 2;
b.SetPixel(centerx, centery, Color.Red);
l.Clear();
++labelnew;
}
label contains the value for each region, starting from 2 and not 0. When I run the code, I get the following error :
Failed to compare two elements in the array
Can someone help me out n tell me what my mistake is