Beispiel #1
0
 public Bitmap Compute(FastImage workImage)
 {
     image = workImage;
     image.Lock();
     DoKirsch();
     image.Unlock();
     return(image.GetBitMap());
 }
        public Bitmap Compute(Point point)
        {
            image.Lock();
            canvas.Lock();
            pointsQueue.Enqueue(point);
            sumaIntensitati += Utils.GetGrayscale(image.GetPixel(point));
            contor++;

            while (pointsQueue.Count > 0)
            {
                var selectedPoint = pointsQueue.Peek();

                if (matriceVizitate[selectedPoint.X, selectedPoint.Y])
                {
                    pointsQueue.Dequeue();
                    continue;
                }

                var limitXmin = selectedPoint.X == 0 ? selectedPoint.X : selectedPoint.X - 1;
                var limitXmax = selectedPoint.X == image.Width - 1 ? selectedPoint.X : selectedPoint.X + 1;
                var limitYmin = selectedPoint.Y == 0 ? 0 : selectedPoint.Y - 1;
                var limitYmax = selectedPoint.Y == image.Height - 1 ? selectedPoint.Y : selectedPoint.Y + 1;

                var pointA = new Point {
                    X = limitXmin, Y = limitYmin
                };
                var pointB = new Point {
                    X = limitXmax, Y = limitYmin
                };
                var pointC = new Point {
                    X = limitXmin, Y = limitYmax
                };
                var pointD = new Point {
                    X = limitXmax, Y = limitYmax
                };

                var culoareA = image.GetPixel(pointA);
                var culoareB = image.GetPixel(pointB);
                var culoareC = image.GetPixel(pointC);
                var culoareD = image.GetPixel(pointD);

                if (Math.Abs(Utils.GetGrayscale(culoareA) - mediaIntensitati) < prag)
                {
                    pointsQueue.Enqueue(pointA);
                }

                if (Math.Abs(Utils.GetGrayscale(culoareB) - mediaIntensitati) < prag)
                {
                    pointsQueue.Enqueue(pointB);
                }

                if (Math.Abs(Utils.GetGrayscale(culoareB) - mediaIntensitati) < prag)
                {
                    pointsQueue.Enqueue(pointC);
                }

                if (Math.Abs(Utils.GetGrayscale(culoareB) - mediaIntensitati) < prag)
                {
                    pointsQueue.Enqueue(pointD);
                }

                sumaIntensitati += Utils.GetGrayscale(image.GetPixel(point));
                contor++;
                matriceVizitate[selectedPoint.X, selectedPoint.Y] = true;
                canvas.SetPixel(selectedPoint, image.GetPixel(selectedPoint));
                pointsQueue.Dequeue();
            }

            image.Unlock();
            canvas.Unlock();

            return(canvas.GetBitMap());
        }