Ejemplo n.º 1
0
        public override Bitmap ProcessImage(Bitmap sourceImage, BackgroundWorker worker)
        {
            Dilation di = new Dilation(diameter);
            Erosion  er = new Erosion(diameter);

            return(er.ProcessImage(di.ProcessImage(sourceImage, worker), worker));
        }
Ejemplo n.º 2
0
        public override Bitmap ProcessImage(Bitmap sourceImage, BackgroundWorker worker)
        {
            width  = sourceImage.Width;
            height = sourceImage.Height;

            Bitmap resultImage = new Bitmap(sourceImage);
            Bitmap tempBitmap  = new Bitmap(width, height);

            int checkProgress = -1;

            using (ImageWrapper wrapTempImage = new ImageWrapper(tempBitmap))
            {
                foreach (var point in wrapTempImage)
                {
                    wrapTempImage[point] = Color.Black;
                }
            }

            Salt     salt     = new Salt(percent);
            Dilation dilation = new Dilation(diameter, kernel);

            tempBitmap = dilation.ProcessImage(salt.ProcessImage(tempBitmap, worker), worker);

            using (ImageWrapper wrapTempImage = new ImageWrapper(tempBitmap))
            {
                using (ImageWrapper wrapImage = new ImageWrapper(resultImage, true))
                {
                    for (int i = 0; i < height; ++i)
                    {
                        if (i > checkProgress)
                        {
                            worker.ReportProgress((int)((double)i / resultImage.Height * 100));
                            if (worker.CancellationPending)
                            {
                                return(null);
                            }

                            checkProgress += 100;
                        }

                        for (int j = 0; j < width; ++j)
                        {
                            Color neighborColor = wrapTempImage[j, i];
                            if (neighborColor.R == 255 && neighborColor.G == 255 && neighborColor.B == 255)
                            {
                                wrapImage[j, i] = wrapTempImage[j, i];
                            }
                        }
                    }
                }
            }

            return(resultImage);
        }