Exemple #1
0
        public static void HighContrastColored(Bitmap img, ContrastFilter filter, HighContastRGB cPlane)
        {
            string imgExtension = GetImageInfo.Imginfo(Imageinfo.Extension);
            string imgName      = GetImageInfo.Imginfo(Imageinfo.FileName);
            string defPath      = GetImageInfo.MyPath("Contrast\\HighContrastFilter");

            Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);

            image = HighContrastProcess(img, filter, cPlane);

            string outName = defPath + imgName + "_" + filter.ToString() + imgExtension;

            Helpers.SaveOptions(image, outName, imgExtension);
        }
        private void contrastButtonClick(object sender, RoutedEventArgs e)
        {
            if (imageHandler != null)
            {
                // TODO Background worker
                new Thread(() =>
                {
                    int contrast          = 50;
                    ContrastFilter filter = new ContrastFilter(contrast);
                    imageHandler.ApplyFilter(image => filter.ApplyFilter(image));

                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
                    {
                        filteredImage.Source = BitmapLoader.loadBitmap(imageHandler.getFiltered());
                    }));
                }).Start();
            }
        }
 private Bitmap RenderImage()
 {
     if (!contrastStretchCB.Checked)
     {
         ContrastFilter filter = new ContrastFilter(valueTrackBar.Value);
         return(filter.ApplyFilter(new List <Bitmap>()
         {
             originalBitmap
         }));
     }
     else
     {
         ContrastStretchFilter filter = new ContrastStretchFilter();
         return(filter.ApplyFilter(new List <Bitmap>()
         {
             originalBitmap
         }));
     }
 }
Exemple #4
0
        public Form1()
        {
            InitializeComponent();
            photo              = new DirectBitmap(GK3.Properties.Resources.Lenna);
            orginalPicture     = new DirectBitmap(GK3.Properties.Resources.Lenna);
            transformedPicture = new DirectBitmap(GK3.Properties.Resources.Lenna);
            ownFunctionPicture = new DirectBitmap(300, 300);

            pictureBox.Image            = photo.Bitmap;
            pictureBoxOwnFunction.Image = ownFunctionPicture.Bitmap;
            polygons = new List <Polygon>();

            isPolygonCreating = false;
            isDrawing         = false;
            ownFunction       = new Vertex[OWN_FUNCTION_POINTS];
            FillFunction(ownFunction);

            setMode(ModeType.AddPolygon);
            filterType = FilterType.NoFilter;

            filter            = new NegationFilter();
            brightnessFilter  = new BrightnessChangeFilter();
            contrastFilter    = new ContrastFilter();
            gammaFilter       = new GammaCorrectionFilter();
            ownFunctionFilter = new OwnFunctionFilter(ownFunction);

            filter.setNext(brightnessFilter);
            brightnessFilter.setNext(contrastFilter);
            contrastFilter.setNext(gammaFilter);
            gammaFilter.setNext(ownFunctionFilter);

            histR.Series[0].Color = Color.Red;
            histG.Series[0].Color = Color.Green;
            histB.Series[0].Color = Color.Blue;

            DrawOwnFunctionAxis();
            DrawOwnFunction();
            UpdatePhoto();
        }
Exemple #5
0
        public static bool ModifyFilter(int index)
        {
            Model.Node     selectedNode = ImageProcessingController.Instance.GetNode(index);
            AbstractFilter filter       = selectedNode.Filter;
            Type           t            = filter.GetType();

            /*
             #region Gaussian Blur Filter : Update
             * if (t == typeof(GaussianBlurFilter)) {
             *  GaussianBlurFilter updatedFilter = (GaussianBlurFilter)filter;
             *  updatedFilter = GaussianBlurForm(updatedFilter);
             *
             *  if (updatedFilter != null) {
             *      ImageProcessingController.Instance.GetNode(index).SetFilter(updatedFilter);
             *      return true;
             *  }
             * }
             #endregion
             *
             #region Gaussian Sharpen Filter : Update
             * if (t == typeof(GaussianSharpenFilter)) {
             *  GaussianSharpenFilter updatedFilter = (GaussianSharpenFilter)filter;
             *  updatedFilter = GaussianSharpenForm(updatedFilter);
             *
             *  if (updatedFilter != null) {
             *      ImageProcessingController.Instance.GetNode(index).SetFilter(updatedFilter);
             *      return true;
             *  }
             * }
             #endregion
             */

            /*
             #region Median Blur Filter : Update
             * if (t == typeof(MedianBlurFilter)) {
             *  MedianBlurFilter updatedFilter = (MedianBlurFilter)filter;
             *  updatedFilter = MedianBlurForm(updatedFilter);
             *
             *  if (updatedFilter != null) {
             *      ImageProcessingController.Instance.GetNode(index).SetFilter(updatedFilter);
             *      return true;
             *  }
             * }
             #endregion
             */

            #region Black White Filter : Update
            if (t == typeof(BlackWhiteFilter))
            {
                BlackWhiteFilter updatedFilter = (BlackWhiteFilter)filter;
                updatedFilter = BlackWhiteForm(selectedNode.Input, updatedFilter);

                if (updatedFilter != null)
                {
                    ImageProcessingController.Instance.GetNode(index).SetFilter(updatedFilter);
                    return(true);
                }
            }
            #endregion


            #region Brightness Filter
            if (t == typeof(BrightnessFilter))
            {
                BrightnessFilter updatedFilter = (BrightnessFilter)filter;
                updatedFilter = BrightnessForm(selectedNode.Input, updatedFilter.Value);

                if (updatedFilter != null)
                {
                    ImageProcessingController.Instance.GetNode(index).SetFilter(updatedFilter);
                    return(true);
                }
            }
            #endregion

            #region Contrast Filter
            if (t == typeof(ContrastFilter))
            {
                ContrastFilter oldFilter = (ContrastFilter)filter;
                AbstractFilter newFilter = ContrastForm(selectedNode.Input, oldFilter.Value);

                if (newFilter != null)
                {
                    ImageProcessingController.Instance.GetNode(index).SetFilter(newFilter);
                    return(true);
                }
            }
            #endregion

            #region Contrast Stretch Filter
            if (t == typeof(ContrastStretchFilter))
            {
                AbstractFilter updatedFilter = ContrastStretchForm(selectedNode.Input);

                if (updatedFilter != null)
                {
                    ImageProcessingController.Instance.GetNode(index).SetFilter(updatedFilter);
                    return(true);
                }
            }
            #endregion

            return(false);
        }
        public void Parse()
        {
            var filter = ContrastFilter.Create(CallSyntax.Parse("contrast(0.5)"));

            Assert.Equal(0.5, filter.Amount);
        }
 public void ThrowsWhenGreaterThan10x()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => ContrastFilter.Create(CallSyntax.Parse("contrast(-1001%)")));
     Assert.Throws <ArgumentOutOfRangeException>(() => ContrastFilter.Create(CallSyntax.Parse("contrast(1001%)")));
 }
        public void SupportsPercentageUnit()
        {
            var filter = ContrastFilter.Create(CallSyntax.Parse("contrast(50%)"));

            Assert.Equal(0.5, filter.Amount);
        }
Exemple #9
0
        private static Bitmap HighContrastProcess(Bitmap img, ContrastFilter filter, HighContastRGB cPlane, [CallerMemberName] string callName = "")
        {
            Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);

            int[,] resultR = new int[img.Height, img.Width];
            int[,] resultG = new int[img.Height, img.Width];
            int[,] resultB = new int[img.Height, img.Width];
            double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat);

            int[,] filterWindow = new int[3, 3];

            if (filter == ContrastFilter.filterOne)
            {
                filterWindow = ImageFilter.Ix3FWindow("HighContrast1");
            }
            else
            {
                filterWindow = ImageFilter.Ix3FWindow("HighContrast2");
            }

            if (callName == "HighContrastBlackWhite")
            {
                if (Depth == 8 || Checks.BlackandWhite24bppCheck(img))
                {
                    var GrayC = MoreHelpers.BlackandWhiteProcessHelper(img);

                    resultR = ImageFilter.Filter_int(GrayC, filterWindow, PadType.replicate);
                    resultG = resultR; resultB = resultR;
                }
                else
                {
                    Console.WriteLine("There non 8bit or 24bit black and white image at input. Method:" + callName);
                }
            }
            else
            {
                if (Checks.RGBinput(img))
                {
                    List <ArraysListInt> ColorList = Helpers.GetPixels(img);

                    switch (cPlane)
                    {
                    case HighContastRGB.R:
                        resultR = ImageFilter.Filter_int(ColorList[0].Color, filterWindow, PadType.replicate);
                        resultG = ColorList[1].Color; resultB = ColorList[2].Color;
                        break;

                    case HighContastRGB.G:
                        resultG = ImageFilter.Filter_int(ColorList[1].Color, filterWindow, PadType.replicate);
                        resultR = ColorList[0].Color; resultB = ColorList[2].Color;
                        break;

                    case HighContastRGB.B:
                        resultB = ImageFilter.Filter_int(ColorList[2].Color, filterWindow, PadType.replicate);
                        resultR = ColorList[0].Color; resultG = ColorList[1].Color;
                        break;

                    case HighContastRGB.RGB:
                        resultR = ImageFilter.Filter_int(ColorList[0].Color, filterWindow, PadType.replicate);
                        resultG = ImageFilter.Filter_int(ColorList[1].Color, filterWindow, PadType.replicate);
                        resultB = ImageFilter.Filter_int(ColorList[2].Color, filterWindow, PadType.replicate);
                        break;
                    }
                }
            }

            image = Helpers.SetPixels(image, resultR, resultG, resultB);
            if (Depth == 8)
            {
                image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image);
            }

            return(image);
        }
Exemple #10
0
 public static Bitmap HighContrastColoredBitmap(Bitmap img, ContrastFilter filter, HighContastRGB cPlane)
 {
     return(HighContrastProcess(img, filter, cPlane));
 }
Exemple #11
0
 public static Bitmap HighContrastBlackWhiteBitmap(Bitmap img, ContrastFilter filter)
 {
     return(HighContrastProcess(img, filter, HighContastRGB.RGB));
 }
Exemple #12
0
        private void OnImageClick(object sender, MouseEventArgs e)
        {
            if (sender == null)
            {
                return;
            }

            if (pBox.Image == null)
            {
                return;
            }

            EditorImage t = (EditorImage)treeView1.SelectedNode.Tag;

            if (t == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                /* Box su cui si è cliccato null altrimenti */
                EditorBox clickedBox = t.GetBox(e.X, e.Y);

                /* Se la zona su cui si è cliccato non ha una box */
                if (clickedBox == EditorBox.None)
                {
                    t.Boxes.FindAll(b => b.IsSelected).ForEach(b => b.ChangeState(t));
                    return;
                }

                if (renderedSelectedBox != clickedBox)
                {
                    if (renderedSelectedBox != EditorBox.None)
                    {
                        renderedSelectedBox?.ChangeState(t);
                    }
                }

                renderedSelectedBox = clickedBox;

                Image rendered = renderedSelectedBox?.ChangeState(t); //365ms

                if (rendered == null)
                {
                    return;
                }

                /* Se è stata selezionata una box imposta l'editor dati */
                SetEditorData(rendered);                              // 1270ms

                pBox.Image.Dispose();
                pBox.Image        = rendered;
                boxEditor.Enabled = true;

                return;
            }

            if (e.Button == MouseButtons.Right)
            {
                FilterOptions fOpts   = new FilterOptions();
                Bitmap        bmpMask = new Bitmap(t.File);

                EditorImage dImg = (EditorImage)treeView1.SelectedNode.Tag;

                bmpMask = new Bitmap(t.File);

                FillRegionDetector det = new FillRegionDetector(e.Location);

                bmpMask = new ContrastFilter(0.8f).Apply(bmpMask);
                det.Apply(bmpMask);

                Rectangle area = det.Detected;

                if (area.Width <= 0 || area.Height <= 0)
                {
                    MessageBox.Show(@"No valid box detected!", @"No box detected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    bmpMask.Dispose();
                    return;
                }

                dImg.AddBox(new EditorBox(new DataBox
                {
                    Top    = area.Top,
                    Left   = area.Left,
                    Height = area.Height,
                    Width  = area.Width,
                    Label  = "new box"
                }));


                bmpMask.Dispose();
                pBox.Image.Dispose();
                pBox.Image = dImg.Render();

                return;
            }
        }