private void InitializeAreaMatrix(ImageWrapper image)
 {
     this._areaMatrix = new int[image.Height][];
     for (int i = 0; i < image.Height; ++i)
     {
         this._areaMatrix[i] = new int[image.Width];
     }
 }
 private void FillPolygons(ImageWrapper image)
 {
     for (int i = 0; i < image.Height; ++i)
     {
         for (int j = 0; j < image.Width; ++j)
         {
             if (this._areaMatrix[i][j] != 0)
             {
                 this._polygons[this._areaMatrix[i][j]].Pixels.Add(new Pixel(i, j, image[i, j]));
             }
         }
     }
 }
        public void Process(ImageWrapper imageWrapper)
        {
            this._histogramm = imageWrapper.GetHistogramm();

            int threshold = this.GetBestThreshold();

            for (int i = 0; i < imageWrapper.Height; ++i)
            {
                for (int j = 0; j < imageWrapper.Width; ++j)
                {
                    imageWrapper[i, j] = imageWrapper[i, j] < threshold ? (byte)0 : byte.MaxValue;
                }
            }
        }
        public IList<Polygon> Process(ImageWrapper image)
        {
            this.InitializeAreaMatrix(image);
            this.InitializeObjectColor(image);
            this.PerformLabeling(image);
            this.ResolveEqualityChains();
            this.LinkPolygons();
            this.FillPolygons(image);

            IList<Polygon> result = this.GetPolygons();

            this._equalityClasses.Clear();
            this._equalityChains.Clear();
            this._polygons.Clear();

            return result;
        }
Esempio n. 5
0
 public ImageProcessor(string fileName)
 {
   this._image = new Bitmap(fileName);
   this._imageWrapper = new ImageWrapper(this._image);
 }
Esempio n. 6
0
 public ImageProcessor(Bitmap image)
 {
   this._image = image;
   this._imageWrapper = new ImageWrapper(image);
 }
 private void InitializeObjectColor(ImageWrapper imageWrapper)
 {
     int blackPixels = imageWrapper.GetColoredPixels(0);
     int whitePixels = imageWrapper.GetColoredPixels(byte.MaxValue);
     this._objectColor = Math.Min(blackPixels, whitePixels) == blackPixels ? 0 : byte.MaxValue;
 }
        private void PerformLabeling(ImageWrapper image)
        {
            this._areaCount = 1;
            for (int i = 1; i < image.Height; ++i)
            {
                for (int j = 1; j < image.Width; ++j)
                {
                    if (image[i, j] == this._objectColor)
                    {
                        int upperNeighbor = this._areaMatrix[i - 1][j];
                        int leftNeighbor = this._areaMatrix[i][j - 1];
                        if (upperNeighbor == 0 && leftNeighbor == 0)
                        {
                            this._areaMatrix[i][j] = this._areaCount++;
                            continue;
                        }

                        if (upperNeighbor != 0 && leftNeighbor == 0)
                        {
                            this._areaMatrix[i][j] = upperNeighbor;
                            continue;
                        }

                        if (upperNeighbor == 0 && leftNeighbor != 0)
                        {
                            this._areaMatrix[i][j] = leftNeighbor;
                            continue;
                        }

                        if (upperNeighbor != 0 && leftNeighbor != 0 && upperNeighbor == leftNeighbor)
                        {
                            this._areaMatrix[i][j] = upperNeighbor;
                            continue;
                        }

                        this._areaMatrix[i][j] = upperNeighbor;
                        this._equalityClasses.Add(new Tuple<int, int>(upperNeighbor, leftNeighbor));
                    }
                }
            }
        }