Beispiel #1
0
        public static void TestChannelModifier()
        {
            var bmp = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(colorImgName);

            var            image = bmp.ToImage <Bgr, byte>();
            UnmanagedImage uIm   = UnmanagedImage.FromManagedImage(bmp);

            measure(() =>
            {
                var hsvIm = image.Convert <Hsv, byte>();

                var hue = new Image <Gray, byte>(hsvIm.Size);
                hue.SetValue(180 / 2);

                hsvIm[Hsv.IdxH] = hue;
                var modifiedIm  = hsvIm.Convert <Bgr, byte>();
            },
                    () =>
            {
                AForge.Imaging.Filters.HueModifier hm = new AForge.Imaging.Filters.HueModifier(180);
                hm.Apply(uIm);
            },
                    100,
                    "Image<,> Hue modifier",
                    "AForge Hue modifier");
        }
        public static void TestChannelModifier()
        {
            var bmp = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(colorImgName);

            var image = bmp.ToImage<Bgr, byte>();
            UnmanagedImage uIm = UnmanagedImage.FromManagedImage(bmp);

            measure(() =>
            {
                var hsvIm = image.Convert<Hsv, byte>();

                var hue = new Image<Gray, byte>(hsvIm.Size);
                hue.SetValue(180 / 2);

                hsvIm[Hsv.IdxH] = hue;
                var modifiedIm = hsvIm.Convert<Bgr, byte>();
            },
            () =>
            {
                AForge.Imaging.Filters.HueModifier hm = new AForge.Imaging.Filters.HueModifier(180);
                hm.Apply(uIm);
            },
            100,
            "Image<,> Hue modifier",
            "AForge Hue modifier");
        }
        private async Task ProcessImage()
        {
            //If we are already waiting on another process request, then stop here.
            if (isImageProcessing)
            {
                return;
            }
            isImageProcessing = true;

            //If enough time has not passed since the last process then we must enter a waiting state
            if (stopwatch.ElapsedMilliseconds < previewDelay)
            {
                for (int wait = 0; wait < previewDelay; wait += previewDelayWait)
                {
                    if (stopwatch.ElapsedMilliseconds >= previewDelay)
                    {
                        break;
                    }
                    await Task.Delay(previewDelayWait);
                }
            }

            //Create System.Drawing.Bitmap
            Bitmap bitmap = (Bitmap)OriginalTextureBackup;
            // Apply filters
            var hueFilter = new AForge.Imaging.Filters.HueModifier(HueValue);


            bitmap = hueFilter.Apply(bitmap);

            //Convert back to WPF Bitmap
            CurrentTexture.DdsImage = (WriteableBitmap)bitmap;

            //Restart the timer
            isImageProcessing = false;
            stopwatch.Restart();
        }
Beispiel #4
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            Bitmap imageoriginal = new Bitmap(imageTest1.Image);
            Image image = imageTest1.Image;

            //Bitmap bmp = new Bitmap(image.Width, image.Height);
            //using (Graphics g = Graphics.FromImage(bmp))
            //{
            //    g.Clear(Color.Transparent);
            //    g.InterpolationMode = InterpolationMode.NearestNeighbor;
            //    g.PixelOffsetMode = PixelOffsetMode.None;
            //    g.DrawImage(image, Point.Empty);
            //}
            Bitmap n = ChangeColor(imageoriginal, colorPickOld.Color, colorPickNew.Color);
            AForge.Imaging.Filters.HueModifier filter = new AForge.Imaging.Filters.HueModifier(142);
            // apply the filter
            System.Drawing.Bitmap newImage = filter.Apply(imageoriginal);

            //int height = imageoriginal.Height;
            //int width = imageoriginal.Width;
            //for (int i = 0; i < width; i++)
            //{
            //    for (int j = 0; j < height; j++)
            //    {
            //        Color origC = imageoriginal.GetPixel(i, j);
            //        Color newC = GetNearestOfBWR(origC, ref imageoriginal);
            //        imageoriginal.SetPixel(i, j, newC);
            //    }
            //}

            imageTest2.Image = (Image)ChangeColor(imageoriginal, new Bitmap(imageTest1.Image.Width, imageTest1.Image.Height), colorPickOld.Color, colorPickNew.Color, colorPicNotChange.Color);

            //imageTest2.Image = TestChangeColor(c, 0, 10, (byte)colorPickNew.Color.GetHue());
        }
Beispiel #5
0
        private void btn_uygula_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0) // Gri seçildi.
            {
                Bitmap image = new Bitmap(pictureBox1.Image);
                Bitmap gri   = griYap(image);

                pictureBox2.Image = gri;
            }
            if (comboBox1.SelectedIndex == 1) // Binary seçildi.
            {
                Bitmap image  = new Bitmap(pictureBox1.Image);
                Bitmap binary = binaryYap(image);
                pictureBox2.Image = binary;
            }
            if (comboBox1.SelectedIndex == 2) // Sobel Kenar seçildi.
            {
                Bitmap image = new Bitmap(pictureBox1.Image);
                Bitmap sobel = sobelEdgeDetection(image);

                pictureBox2.Image = sobel;
            }
            if (comboBox1.SelectedIndex == 3) // Sobel Kenar seçildi.
            {
                Bitmap image  = new Bitmap(pictureBox1.Image);
                Bitmap median = medianFilter(image);

                pictureBox2.Image = median;
            }
            if (comboBox1.SelectedIndex == 4) // Sepia Fitreleme seçildi.
            {
                // load an image
                System.Drawing.Bitmap image = new Bitmap(pictureBox1.Image);
                // create filter
                AForge.Imaging.Filters.Sepia filter = new AForge.Imaging.Filters.Sepia();
                // apply filter
                System.Drawing.Bitmap newImage = filter.Apply(image);


                pictureBox2.Image = newImage;
            }
            if (comboBox1.SelectedIndex == 5) // Blur Fitreleme seçildi.
            {
                // load an image
                System.Drawing.Bitmap image = new Bitmap(pictureBox1.Image);
                // create filter
                AForge.Imaging.Filters.Blur filter = new AForge.Imaging.Filters.Blur();
                // apply filter
                System.Drawing.Bitmap newImage = filter.Apply(image);


                pictureBox2.Image = newImage;
            }
            if (comboBox1.SelectedIndex == 6) // Keskinleştirme Fitreleme seçildi.
            {
                // load an image
                System.Drawing.Bitmap image = new Bitmap(pictureBox1.Image);
                // create filter
                AForge.Imaging.Filters.Sharpen filter = new AForge.Imaging.Filters.Sharpen();
                // apply filter
                System.Drawing.Bitmap newImage = filter.Apply(image);

                pictureBox2.Image = newImage;
            }
            if (comboBox1.SelectedIndex == 7) // Hue Modifier Fitreleme seçildi.
            {
                // load an image
                System.Drawing.Bitmap image = new Bitmap(pictureBox1.Image);
                // create filter
                AForge.Imaging.Filters.HueModifier filter = new AForge.Imaging.Filters.HueModifier();
                // apply filter
                System.Drawing.Bitmap newImage = filter.Apply(image);

                pictureBox2.Image = newImage;
            }
        }
Beispiel #6
0
        //Make this an extension method so there's not an AForge dependence wherever EMB is used
        public static void ChangeHue(this EmbEntry entry, double hue, double _saturation, double lightness, List <IUndoRedo> undos = null, bool hueSet = false, int variance = 0)
        {
            float brightness = (float)lightness / 5f;
            float saturation = (float)_saturation;

            WriteableBitmap oldBitmap = entry.DdsImage;
            Bitmap          bitmap    = (Bitmap)entry.DdsImage;

            if (hueSet)
            {
                if (variance != 0)
                {
                    hue += Random.Range(-variance, variance);
                }

                var hueFilter = new AForge.Imaging.Filters.HueModifier((int)hue);
                hueFilter.ApplyInPlace(bitmap);
            }
            else
            {
                //Hue Adjustment (shifting)

                // Apply filters
                var hueFilter = new AForge.Imaging.Filters.HueAdjustment((int)hue);
                var hslFilter = new AForge.Imaging.Filters.HSLLinear();

                //Apply filters
                hueFilter.ApplyInPlace(bitmap);

                if (lightness > 0 || saturation > 0)
                {
                    //Taken from: https://csharp.hotexamples.com/examples/AForge.Imaging.Filters/HSLLinear/-/php-hsllinear-class-examples.html
                    // create luminance filter
                    if (brightness > 0)
                    {
                        hslFilter.InLuminance  = new Range(0.0f, 1.0f - brightness); //TODO - isn't it better not to truncate, but compress?
                        hslFilter.OutLuminance = new Range(brightness, 1.0f);
                    }
                    else
                    {
                        hslFilter.InLuminance  = new Range(-brightness, 1.0f);
                        hslFilter.OutLuminance = new Range(0.0f, 1.0f + brightness);
                    }
                    // create saturation filter
                    if (saturation > 0)
                    {
                        hslFilter.InSaturation  = new Range(0.0f, 1.0f - saturation); //Ditto?
                        hslFilter.OutSaturation = new Range(saturation, 1.0f);
                    }
                    else
                    {
                        hslFilter.InSaturation  = new Range(-saturation, 1.0f);
                        hslFilter.OutSaturation = new Range(0.0f, 1.0f + saturation);
                    }

                    if (hslFilter.FormatTranslations.ContainsKey(bitmap.PixelFormat))
                    {
                        hslFilter.ApplyInPlace(bitmap);
                    }
                }
            }

            //Convert back to WPF Bitmap
            entry.DdsImage  = (WriteableBitmap)bitmap;
            entry.wasEdited = true;

            if (undos != null)
            {
                undos.Add(new UndoableProperty <EmbEntry>(nameof(EmbEntry.DdsImage), entry, oldBitmap, entry.DdsImage));
            }
        }