public WatershedStructure(Bitmap image)
        {
            Structure = new WatershedPixel[image.Width, image.Height];

            //Remplissage du tableau
            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    int gsv = (image.GetPixel(x, y).R + image.GetPixel(x, y).G + image.GetPixel(x, y).B) / 3;
                    Structure[x, y] = new WatershedPixel(x, y, gsv);
                }
            }

            //Références des voisins
            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    WatershedPixel wp = Structure[x, y];

                    for (int i = -1; i < 2; i++)
                    {
                        for (int j = -1; j < 2; j++)
                        {
                            if (i != 0 || j != 0)
                            {
                                try
                                {
                                    wp.addNeighbour(Structure[x + i, y + j]);
                                }
                                catch (IndexOutOfRangeException e) { }
                            }
                        }
                    }
                    wp.initDepth();
                }
            }
        }
Beispiel #2
0
        public MeyerStruct(Bitmap image)
        {
            Structure = new List <WatershedPixel>();
            int width  = image.Width;
            int height = image.Height;

            //Remplissage du tableau
            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    int gsv = (image.GetPixel(x, y).R + image.GetPixel(x, y).G + image.GetPixel(x, y).B) / 3;
                    Structure.Add(new WatershedPixel(x, y, gsv));
                }
            }
            for (int y = 0; y < height; y++)
            {
                int offset       = y * width;
                int topOffset    = offset + width;
                int bottomOffset = offset - width;
                for (int x = 0; x < width; x++)
                {
                    WatershedPixel currentPixel = (WatershedPixel)Structure.ElementAt(x + offset);

                    if (x + 1 < width)
                    {
                        currentPixel.addNeighbour((WatershedPixel)Structure.ElementAt(x + 1 + offset));

                        if (y - 1 >= 0)
                        {
                            currentPixel.addNeighbour((WatershedPixel)Structure.ElementAt(x + 1 + bottomOffset));
                        }

                        if (y + 1 < height)
                        {
                            currentPixel.addNeighbour((WatershedPixel)Structure.ElementAt(x + 1 + topOffset));
                        }
                    }

                    if (x - 1 >= 0)
                    {
                        currentPixel.addNeighbour((WatershedPixel)Structure.ElementAt(x - 1 + offset));

                        if (y - 1 >= 0)
                        {
                            currentPixel.addNeighbour((WatershedPixel)Structure.ElementAt(x - 1 + bottomOffset));
                        }

                        if (y + 1 < height)
                        {
                            currentPixel.addNeighbour((WatershedPixel)Structure.ElementAt(x - 1 + topOffset));
                        }
                    }

                    if (y - 1 >= 0)
                    {
                        currentPixel.addNeighbour((WatershedPixel)Structure.ElementAt(x + bottomOffset));
                    }

                    if (y + 1 < height)
                    {
                        currentPixel.addNeighbour((WatershedPixel)Structure.ElementAt(x + topOffset));
                    }
                }
            }

            Structure.Sort();
        }