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)
                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);

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

What is I[j, i] ? a point defined in the l lList? You cannot compare ints with Points if that is the case. Suggestion : Give more meaningfull names to your variables instead of I or l.

This question has already been answered. Start a new discussion instead.