0

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

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by sathya8819
0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.