Example #1
2
        private Bitmap Flatten(Bitmap bmp, int fillint, int contint)
        {
            ColorFiltering colorFilter = new ColorFiltering();

            colorFilter.Red = new IntRange(0, fillint);
            colorFilter.Green = new IntRange(0, fillint);
            colorFilter.Blue = new IntRange(0, fillint);
            colorFilter.FillOutsideRange = false;
            using (Bitmap filteredBmp = colorFilter.Apply(bmp))
            {
                AForge.Imaging.Filters.ContrastCorrection Contrast = new ContrastCorrection(contint);
                AForge.Imaging.Filters.Invert invert = new Invert();
                AForge.Imaging.Filters.ExtractChannel extract_channel = new ExtractChannel(RGB.B);
                AForge.Imaging.Filters.Threshold thresh_hold = new Threshold(44);

                Contrast.ApplyInPlace(filteredBmp);

                Bitmap extractedBmp = extract_channel.Apply(filteredBmp);
                thresh_hold.ApplyInPlace(extractedBmp);
                invert.ApplyInPlace(extractedBmp);

                return extractedBmp;
            }
        }
		/// <summary>
		/// Adjust contrast in RGB colour space.
		/// </summary>
		/// <param name="bitmap">The bitmap.</param>
		public static Bitmap Contrast(this Bitmap bitmap) {
			if ((bitmap = bitmap.Channel()) != null) {
				var contrastCorrection = new ContrastCorrection();
				contrastCorrection.ApplyInPlace(bitmap);
			}
			return bitmap;
		}
 /// <summary>
 /// Adjust contrast in RGB colour space.
 /// </summary>
 public static Bitmap Contrast(this Bitmap Bitmap)
 {
     // Convert grayscale to RGB colour space.
     if ((Bitmap = Bitmap.Channel()) != null) {
         // Initialize a new instance of the ContrastCorrection class.
         var ContrastCorrection = new ContrastCorrection();
         // Apply the filter to the image.
         ContrastCorrection.ApplyInPlace(Bitmap);
     }
     // Return the bitmap.
     return Bitmap;
 }
Example #4
0
        // Process image
        private void ProcessImage(Bitmap bitmap)
        {
            // create filter
            HistogramEqualization hisFilter = new HistogramEqualization();
            // process image
            //hisFilter.ApplyInPlace(Image);

            // create filter
            ContrastCorrection contrastFilter = new ContrastCorrection(4);
            // apply the filter
            contrastFilter.ApplyInPlace(bitmap);

            //QuantizeImage(bitmap);

            Grayscale grayscaleFilter = new Grayscale(0.33, 0.33, 0.34);
            // apply the filter
            Bitmap grayImage = grayscaleFilter.Apply(bitmap);

            // create filter
            SobelEdgeDetector sobelFilter = new SobelEdgeDetector();
            // apply the filter
            sobelFilter.ApplyInPlace(grayImage);
            Threshold filter = new Threshold(110);
            // apply the filter
            filter.ApplyInPlace(grayImage);

            if (GetIntersect(grayImage, bitmap, intersectPoint)) {
                //MessageBox.Show("draw");
                Graphics g = Graphics.FromImage(bitmap);
                //Sorting

                for (int i = 0; i < 19; i++)
                {
                    for (int j = 0; j < 19; j++)
                    {
                        for (int k = 0; k < 19 - 1; k++)
                        {
                            if (Math.Abs(intersectPoint[1, i, k]) > Math.Abs(intersectPoint[1, i, k + 1]))
                            {
                                int tempX = Math.Abs(intersectPoint[0, i, k]);
                                int tempY = Math.Abs(intersectPoint[1, i, k]);
                                intersectPoint[0, i, k] = Math.Abs(intersectPoint[0, i, k + 1]);
                                intersectPoint[1, i, k] = Math.Abs(intersectPoint[1, i, k + 1]);
                                intersectPoint[0, i, k + 1] = tempX;
                                intersectPoint[1, i, k + 1] = tempY;
                                //MessageBox.Show(i + " " + k +" " +tempX + " " + tempY + " " + intersectPoint[0, i, k] + " " + intersectPoint[1, i, k] ,"ok", MessageBoxButtons.OK);
                            }
                        }
                    }
                }

                for (int i = 0; i < 19; i++)
                {
                    for (int j = 0; j < 19; j++)
                    {
                        for (int k = 0; k < 19 - 1; k++)
                        {
                            if (Math.Abs(intersectPoint[0, k, i]) > Math.Abs(intersectPoint[0, k + 1, i]))
                            {
                                int tempX = Math.Abs(intersectPoint[0, k, i]);
                                int tempY = Math.Abs(intersectPoint[1, k, i]);
                                intersectPoint[0, k, i] = intersectPoint[0, k + 1, i];
                                intersectPoint[1, k, i] = intersectPoint[1, k + 1, i];
                                intersectPoint[0, k + 1, i] = tempX;
                                intersectPoint[1, k + 1, i] = tempY;
                            }
                        }
                    }
                }

                Pen redPen = new Pen(Color.Red, 4);
                for (int i = 0; i < 19; i++)
                {
                    for (int j = 0; j < 19; j++)
                    {
                        g.DrawEllipse(redPen, Math.Abs(intersectPoint[0, i, j]) , Math.Abs(intersectPoint[1, i, j]) , (int)5, (int)5);
                        //g.DrawEllipse(redPen, 0, 0, (int)5, (int)5);

                        //Debug.WriteLine((Math.Abs(intersectPoint[0, i, j]) - 2) + " " + (Math.Abs(intersectPoint[1, i, j]) - 2));
                    }
                }

                Pen greenPen = new Pen(Color.Green, 4);

                greenPen.Dispose();
                redPen.Dispose();
                g.Dispose();

                // Initializes the variables to pass to the MessageBox.Show method.
                EspacioCamera.Image = bitmap;
                string message = "Do you accecpt this detection?";
                string caption = "The system found totally 38 lines.";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult result;

                // Displays the MessageBox.

                result = MessageBox.Show(message, caption, buttons);

                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    // Closes the parent form.
                    locked = true;
                }
            }

            EspacioCamera.Image = bitmap;
        }
Example #5
0
        /// <summary>
        /// Modifica el brillo y contraste de la imagen que aparece en pantalla
        /// </summary>
        private void Filtrar()
        {
            Bitmap temp = new Bitmap(padre.actual.datacuboHigh.dataCube[trackElementos.Value - 1].bmp);

            AForge.Imaging.Filters.BrightnessCorrection brillo = new AForge.Imaging.Filters.BrightnessCorrection(Convert.ToInt32(trackBrillo.Value));
            AForge.Imaging.Filters.ContrastCorrection contraste = new AForge.Imaging.Filters.ContrastCorrection(Convert.ToInt32(trackContraste.Value));

            contraste.ApplyInPlace(temp);
            brillo.ApplyInPlace(temp);

            pictElemento.Image = temp;

            //pictElemento.Invalidate();
        }
Example #6
0
        public static bool ColorCorrections(string fileName, int brightness, int contrast, double gamma, int hue, float saturation)
        {
            if (String.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName");

            bool result = false;

            using (var ms = new MemoryStream(File.ReadAllBytes(fileName)))
            {
                using (Bitmap bmp = new Bitmap(ms))
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10
                    if (brightness >= -255 && brightness != 0 && brightness <= 255)
                    {
                        BrightnessCorrection filter = new BrightnessCorrection(brightness);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10
                    if (contrast >= -127 && contrast != 0 && contrast <= 127)
                    {
                        ContrastCorrection filter = new ContrastCorrection(contrast);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0
                    if (gamma >= 0.1D && gamma != 1D && gamma <= 5D)
                    {
                        GammaCorrection filter = new GammaCorrection(gamma);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0
                    if (hue >= -180 && hue != 0 && hue <= 180)
                    {
                        HueModifier filter = new HueModifier(hue);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1
                    if (saturation >= -100f && saturation != 0f && saturation <= 100f)
                    {
                        SaturationCorrection filter = new SaturationCorrection(saturation / 100);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    bmp.Save(fileName);
                }
            }

            return result;
        }
Example #7
0
        public static BitmapSource ColorCorrections(BitmapSource source, int brightness, int contrast, double gamma, int hue, float saturation)
        {
            if (source == null) throw new ArgumentNullException("source");

            BitmapSource output = null;

            if (source.Format == PixelFormats.Bgr32 && gamma != 1D)
            {
                source = new FormatConvertedBitmap(source, PixelFormats.Bgr24, null, 0);
            }

            using (Bitmap bmp = Convert(source))
            {
                int bpp = source.Format.BitsPerPixel;

                if (bpp == 8 || bpp == 24 || bpp == 32)
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10
                    if (brightness >= -255 && brightness != 0 && brightness <= 255)
                    {
                        BrightnessCorrection filter = new BrightnessCorrection(brightness);
                        filter.ApplyInPlace(bmp);
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10
                    if (contrast >= -127 && contrast != 0 && contrast <= 127)
                    {
                        ContrastCorrection filter = new ContrastCorrection(contrast);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 8 || bpp == 24)
                {
                    //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0
                    if (gamma >= 0.1D && gamma != 1D && gamma <= 5D)
                    {
                        GammaCorrection filter = new GammaCorrection(gamma);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 8 || bpp == 24 || bpp == 32)
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0
                    if (hue >= -180 && hue != 0 && hue <= 180)
                    {
                        HueModifier filter = new HueModifier(hue);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 24 || bpp == 32)
                {
                    //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1
                    if (saturation >= -100f && saturation != 0f && saturation <= 100f)
                    {
                        SaturationCorrection filter = new SaturationCorrection(saturation / 100);
                        filter.ApplyInPlace(bmp);
                    }
                }

                output = Convert(bmp);
            }

            return CloneImage(output);
        }
Example #8
0
        /// <summary>
        /// [Português]
        /// Método que realiza a subtração entre duas imagens.
        /// <para></para>
        /// [English]
        /// Method that performs the subtraction between two images.
        /// </summary>
        /// <param name="patientImg"></param>
        /// <param name="backgroundImg"></param>
        /// <returns></returns>
        public Bitmap ProcessImage(Bitmap patientImg, Bitmap backgroundImg)
        {
            //#if RELEASE
            backgroundImg.SetResolution(96, 96);
            patientImg.SetResolution(96, 96);

            var subtract = new AForge.Imaging.Filters.Subtract(backgroundImg);
            subtract.ApplyInPlace(patientImg);

            var contrast = new AForge.Imaging.Filters.ContrastCorrection(60);
            contrast.ApplyInPlace(patientImg);

            Grayscale escalaCinza = Grayscale.CommonAlgorithms.BT709;
            patientImg = escalaCinza.Apply(patientImg);

            Threshold threshold = new Threshold(10);
            threshold.ApplyInPlace(patientImg);
            return patientImg;
            //#endif
        }