Пример #1
0
 public void DoWatershed(ImageData toCompute, int isOkAltitude)
 {
     this.zonesMap = Watershed.AllocZoneMap(toCompute.image.Width, toCompute.image.Height);
     this.FindZero(toCompute);
     for (int greyLevelIndex = 0; greyLevelIndex < 256; greyLevelIndex++)
     {
         for (int yIndex = 0; yIndex < toCompute.image.Height; yIndex++)
         {
             for (int xIndex = 0; xIndex < toCompute.image.Width; xIndex++)
             {
                 int pixelGreyScale = HSVColor.HSVtoGreyLevelRGB(HSVColor.RGBtoHSV(toCompute.image.GetPixel(xIndex, yIndex))).B;
                 if ((this.zonesMap[yIndex][xIndex] != 0) && (pixelGreyScale >= greyLevelIndex) && (pixelGreyScale <= greyLevelIndex + isOkAltitude))
                 {
                     for (int yWindow = yIndex - 1; yWindow < yIndex + 2; yWindow++)
                     {
                         for (int xWindow = xIndex - 1; xWindow < xIndex + 2; xWindow++)
                         {
                             if ((yIndex < 0) || (yIndex >= toCompute.image.Height) || (xIndex < 0) || (xIndex >= toCompute.image.Width))
                             {
                                 continue;
                             }
                             else if (this.zonesMap[yWindow][xWindow] == 0)
                             {
                                 this.zonesMap[yWindow][xWindow] = this.zonesMap[yIndex][xIndex];
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #2
0
        private static Point CheckPoint(ImageData toCompute, int element)
        {
            List <Point> possiblePoints = new List <Point>();
            Random       random         = new Random();

            for (int yIndex = 0; yIndex < toCompute.image.Height; yIndex++)
            {
                for (int xIndex = 0; xIndex < toCompute.image.Width; xIndex++)
                {
                    Color pixelColor = toCompute.image.GetPixel(xIndex, yIndex);
                    if (element == HSVColor.HSVtoGreyLevelRGB(HSVColor.RGBtoHSV(pixelColor)).B)
                    {
                        possiblePoints.Add(new Point(xIndex, yIndex));
                    }
                }
            }
            if (possiblePoints.Count == 0)
            {
                return(null);
            }
            else
            {
                return(possiblePoints[random.Next(possiblePoints.Count)]);
            }
        }
Пример #3
0
        private void FindZero(ImageData toCompute)
        {
            int minimumGreyValue = 0;

            for (int indexGrey = 0; indexGrey < 256; indexGrey++)
            {
                if (toCompute.histogram[indexGrey] != 0)
                {
                    minimumGreyValue = indexGrey;
                    break;
                }
            }
            for (int yIndex = 0; yIndex < toCompute.image.Height; yIndex++)
            {
                for (int xIndex = 0; xIndex < toCompute.image.Width; xIndex++)
                {
                    if (HSVColor.HSVtoGreyLevelRGB(HSVColor.RGBtoHSV(toCompute.image.GetPixel(xIndex, yIndex))).B == minimumGreyValue)
                    {
                        int notAround = 0;
                        for (int yWindow = yIndex - 1; yWindow < yIndex + 2; yWindow++)
                        {
                            for (int xWindow = xIndex - 1; xWindow < xIndex + 2; xWindow++)
                            {
                                if ((yIndex < 0) || (yIndex >= toCompute.image.Height) || (xIndex < 0) || (xIndex >= toCompute.image.Width))
                                {
                                    continue;
                                }
                                else if (this.zonesMap[yWindow][xWindow] != 0)
                                {
                                    notAround = this.zonesMap[yWindow][xWindow];
                                }
                            }
                        }
                        if (notAround == 0)
                        {
                            markNumber++;
                            this.zonesMap[yIndex][xIndex] = markNumber;
                        }
                        else
                        {
                            this.zonesMap[yIndex][xIndex] = markNumber;
                        }
                    }
                }
            }
        }
Пример #4
0
        public void GetHistogramFromColoredImage()   //Calculate the histogram from a colored image
        {
            CreateHistogram();
            List <HSVColor> colorList = new List <HSVColor>();

            for (int yIndex = 0; yIndex < this.image.Height; yIndex++)
            {
                for (int xIndex = 0; xIndex < this.image.Width; xIndex++)
                {
                    colorList.Add(HSVColor.RGBtoHSV(this.image.GetPixel(xIndex, yIndex)));
                }
            }
            foreach (HSVColor element in colorList)
            {
                int greyLevel = HSVColor.HSVtoGreyLevelRGB(element).B;
                this.histogram[greyLevel]++;
            }
        }
Пример #5
0
        private TailRecursionResult <int[][]> DoDilation(ImageData toCompute, List <Point> seedsList, int[][] map)
        {
            int isNotPossible = 0;

            foreach (Point point in seedsList)
            {
                int sum          = 0;
                int pixelCounter = 0;
                for (int yIndex = point.y - 1; yIndex < point.y + 2; yIndex++)
                {
                    for (int xIndex = point.x - 1; xIndex < point.x + 2; xIndex++)
                    {
                        if ((yIndex < 0) || (yIndex >= toCompute.image.Height) || (xIndex < 0) || (xIndex >= toCompute.image.Width))
                        {
                            continue;
                        }
                        else if (zonesMap[yIndex][xIndex] == 0)
                        {
                            sum = sum + HSVColor.HSVtoGreyLevelRGB(HSVColor.RGBtoHSV(toCompute.image.GetPixel(xIndex, yIndex))).R;
                            pixelCounter++;
                        }
                    }
                }
                if (pixelCounter == 0)
                {
                    isNotPossible++;
                }
                else
                {
                    int mean      = (int)(sum / pixelCounter);
                    int greyLevel = HSVColor.HSVtoGreyLevelRGB(HSVColor.RGBtoHSV(toCompute.image.GetPixel(point.x, point.y))).R;
                    if ((mean < greyLevel - 8) || (mean > greyLevel + 8))
                    {
                        isNotPossible++;
                    }
                    else
                    {
                        for (int yIndex = point.y - 1; yIndex < point.y + 2; yIndex++)
                        {
                            for (int xIndex = point.x - 1; xIndex < point.x + 2; xIndex++)
                            {
                                if ((yIndex < 0) || (yIndex >= toCompute.image.Height) || (xIndex < 0) || (xIndex >= toCompute.image.Width))
                                {
                                    continue;
                                }
                                else
                                {
                                    zonesMap[yIndex][xIndex] = point.mark;
                                }
                            }
                        }
                    }
                }
            }
            if (isNotPossible == seedsList.Count)
            {
                return(End(zonesMap));
            }
            else
            {
                seedsList = RefillSeedsFromZonesMap(seedsList, zonesMap);
                return(Next(() => DoDilation(toCompute, seedsList, zonesMap)));
            }
        }