Example #1
0
 private List<WatershedPixel> GetNeighbouringPixels(WatershedPixel centerPixel)
 {
     List<WatershedPixel> temp = new List<WatershedPixel>();
     if (_numberOfNeighbours == 8)
     {
         /*
         CP = Center pixel
         (X,Y) -- get all 8 connected
         |-1,-1|0,-1|1,-1|
         |-1, 0| CP |1, 0|
         |-1,+1|0,+1|1,+1|
         */
         // -1, -1
         if ((centerPixel.X - 1) >= 0 && (centerPixel.Y - 1) >= 0)
             temp.Add(_pixelMap[(centerPixel.X - 1).ToString() + "," + (centerPixel.Y - 1).ToString()]);
         //  0, -1
         if ((centerPixel.Y - 1) >= 0)
             temp.Add(_pixelMap[centerPixel.X.ToString() + "," + (centerPixel.Y - 1).ToString()]);
         //  1, -1
         if ((centerPixel.X + 1) < _pictureWidth && (centerPixel.Y - 1) >= 0)
             temp.Add(_pixelMap[(centerPixel.X + 1).ToString() + "," + (centerPixel.Y - 1).ToString()]);
         // -1, 0
         if ((centerPixel.X - 1) >= 0)
             temp.Add(_pixelMap[(centerPixel.X - 1).ToString() + "," + centerPixel.Y.ToString()]);
         //  1, 0
         if ((centerPixel.X + 1) < _pictureWidth)
             temp.Add(_pixelMap[(centerPixel.X + 1).ToString() + "," + centerPixel.Y.ToString()]);
         // -1, 1
         if ((centerPixel.X - 1) >= 0 && (centerPixel.Y + 1) < _pictureHeight)
             temp.Add(_pixelMap[(centerPixel.X - 1).ToString() + "," + (centerPixel.Y + 1).ToString()]);
         //  0, 1
         if ((centerPixel.Y + 1) < _pictureHeight)
             temp.Add(_pixelMap[centerPixel.X.ToString() + "," + (centerPixel.Y + 1).ToString()]);
         //  1, 1
         if ((centerPixel.X + 1) < _pictureWidth && (centerPixel.Y + 1) < _pictureHeight)
             temp.Add(_pixelMap[(centerPixel.X + 1).ToString() + "," + (centerPixel.Y + 1).ToString()]);
     }
     else
     {
         /*
         CP = Center pixel, N/A = not used
         (X,Y) -- get only 4 connected
         | N/A |0,-1| N/A |
         |-1, 0| CP |+1, 0|
         | N/A |0,+1| N/A |
         */
         //  -1, 0
         if ((centerPixel.X - 1) >= 0)
             temp.Add(_pixelMap[(centerPixel.X - 1).ToString() + "," + centerPixel.Y.ToString()]);
         //  0, -1
         if ((centerPixel.Y - 1) >= 0)
             temp.Add(_pixelMap[centerPixel.X.ToString() + "," + (centerPixel.Y - 1).ToString()]);
         //  1, 0
         if ((centerPixel.X + 1) < _pictureWidth)
             temp.Add(_pixelMap[(centerPixel.X + 1).ToString() + "," + centerPixel.Y.ToString()]);
         //  0, 1
         if ((centerPixel.Y + 1) < _pictureHeight)
             temp.Add(_pixelMap[centerPixel.X.ToString() + "," + (centerPixel.Y + 1).ToString()]);
     }
     return temp;
 }
Example #2
0
 public void AddToEnd(WatershedPixel p)
 {
     queue.Add(p);
 }
Example #3
0
        private void CreatePixelMapAndHeightSortedArray(BitmapData data)
        {
            _pictureWidth = data.Width;
            _pictureHeight = data.Height;
            // pixel map holds every pixel thus size of (_pictureWidth * _pictureHeight)
            _pixelMap = new Dictionary<string, WatershedPixel>(_pictureWidth * _pictureHeight);
            unsafe
            {
                int offset = data.Stride - data.Width;
                byte* ptr = (byte*)(data.Scan0);

                // get histogram of all values in grey = height
                for (int y = 0; y < data.Height; y++)
                {
                    for (int x = 0; x < data.Width; x++, ptr++)
                    {
                        WatershedPixel p = new WatershedPixel(x, y, *ptr);
                        // add every pixel to the pixel map
                        _pixelMap.Add(p.X.ToString() + "," + p.Y.ToString(), p);
                        _heightSortedList[*ptr].Add(p);
                    }
                    ptr += offset;
                }
            }
            this._currentLabel = 0;
        }