Beispiel #1
0
        private void reapplyToolStripMenuItem4_Click(object sender, EventArgs e)
        {
            //GrayscaleBT709 grayObject = new GrayscaleBT709();
            //pictureBox2.Image = grayObject.Apply((Bitmap)pictureBox2.Image);
            HomogenityEdgeDetector filter = new HomogenityEdgeDetector();

            pictureBox2.Image = filter.Apply((Bitmap)pictureBox2.Image);
        }
        public Bitmap GetNewFrame(Bitmap source)
        {
            var source1  = Grayscale.CommonAlgorithms.RMY.Apply(source);
            var newFrame = homogenityEdgeDetector.Apply(source1);

            source.Dispose();
            source1.Dispose();
            return(newFrame);
        }
 public void HomogenityClickHandler(object sender, EventArgs e)
 {
     if (image != null)
     {
         Bitmap imx = new Bitmap(path);
         imx = Grayscale.CommonAlgorithms.Y.Apply(imx);
         HomogenityEdgeDetector gb = new HomogenityEdgeDetector();
         imx = gb.Apply(imx);
         if (mov != null)
         {
             this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Close(mov);
         }
         mov = this.WorkItem.SmartParts.AddNew <ImageAView>();
         mov.panAndZoomPictureBox1.Image = imx;
         SmartPartInfo spi =
             new SmartPartInfo("Homogenity", "MyOwnDescription");
         this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Show(mov, spi);
     }
 }
Beispiel #4
0
        public static Bitmap FilterImage(Bitmap img, int filter)
        {
            Bitmap sourceImage = img;

            sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            IFilter myFilter;
            Bitmap  filteredImage = sourceImage;

            if (filter == Filters.filters["Greyscale"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                filteredImage = sourceImage;
            }
            else if (filter == Filters.filters["Sepia"])
            {
                myFilter      = new Sepia();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Invert"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Invert();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["RotateChannel"])
            {
                myFilter      = new RotateChannels();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Threshold"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new Threshold();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["FloydFilter"])
            {
                FloydSteinbergColorDithering myReduction = new FloydSteinbergColorDithering();
                filteredImage = myReduction.Apply(sourceImage);
            }
            else if (filter == Filters.filters["OrderedDithering"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new OrderedDithering();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Sharpen"])
            {
                myFilter      = new Sharpen();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["DifferenceEdgeDetector"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new DifferenceEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["HomogenityEdgeDetector"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new HomogenityEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Sobel"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new SobelEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Jitter"])
            {
                myFilter      = new Jitter(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["OilPainting"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new OilPainting(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["TextureFiltering"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Texturer(new TextileTexture(), 1.0, 0.8); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Median"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Median();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Mean"])
            {
                myFilter      = new Mean();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Blur"])
            {
                myFilter      = new GaussianBlur();
                filteredImage = myFilter.Apply(sourceImage);
            }

            //Console.Write(filteredImage.PixelFormat.ToString());
            //Console.Write(sourceImage.PixelFormat.ToString());
            filteredImage = ImageUtil.convert(filteredImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            return(filteredImage);
        }
Beispiel #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Bitmap sourceImage = null;

            DA.GetData(0, ref sourceImage);
            string filter = "";

            DA.GetData(1, ref filter);


            sourceImage = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            IFilter myFilter;
            Bitmap  filteredImage = sourceImage;

            //Grayscale.CommonAlgorithms.Y.Apply
            switch (filter)
            {
            case "Greyscale":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                filteredImage = sourceImage;
                break;

            case "Sepia":
                Console.Write("Applying: " + filter);
                myFilter      = new Sepia();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Invert":
                Console.Write("Applying: " + filter);
                sourceImage   = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Invert();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "RotateChannel":
                Console.Write("Applying: " + filter);
                myFilter      = new RotateChannels();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Threshold":     //Need Extended Version
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new Threshold();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "FloydFilter":
                Console.Write("Applying: " + filter);
                //sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                //myFilter = new FloydSteinbergColorDithering();
                FloydSteinbergColorDithering myReduction = new FloydSteinbergColorDithering();
                filteredImage = myReduction.Apply(sourceImage);
                //filteredImage = myFilter.Apply(sourceImage);
                break;

            case "OrderedDithering":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new OrderedDithering();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Sharpen":
                Console.Write("Applying: " + filter);
                myFilter      = new Sharpen();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "DifferenceEdgeDetector":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new DifferenceEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "HomogenityEdgeDetector":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new HomogenityEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Sobel":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new SobelEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Jitter":
                Console.Write("Applying: " + filter);
                myFilter      = new Jitter(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "OilPainting":
                Console.Write("Applying: " + filter);
                myFilter      = new OilPainting(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "TextureFiltering":
                Console.Write("Applying: " + filter);
                sourceImage   = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Texturer(new TextileTexture(), 1.0, 0.8); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Median":
                Console.Write("Applying: " + filter);
                myFilter      = new Median();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Mean":
                Console.Write("Applying: " + filter);
                myFilter      = new Mean();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Blur":     //Need Extended Version
                Console.Write("Applying: " + filter);
                myFilter      = new GaussianBlur();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            default:
                Console.Write("No Filter");
                break;
            }

            Console.Write(filteredImage.PixelFormat.ToString());
            Console.Write(sourceImage.PixelFormat.ToString());
            filteredImage = ImageUtilities.convert(filteredImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);



            DA.SetData(0, filteredImage);
        }
        public override Bitmap ApplyFilter(List <Bitmap> bitmaps)
        {
            HomogenityEdgeDetector filter = new HomogenityEdgeDetector();

            return(filter.Apply(bitmaps[0].ConvertPixelFormat(PixelFormat.Format16bppGrayScale)));
        }
Beispiel #7
0
        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            loaded            = new Bitmap(openFileDialog1.FileName);
            pictureBox1.Image = loaded;

            processed = new Bitmap(openFileDialog1.FileName);

            GrayscaleBT709 g = new GrayscaleBT709();

            processed = g.Apply((Bitmap)processed);

            Threshold t = new Threshold(128);

            processed = t.Apply((Bitmap)processed);

            BlobsFiltering b = new BlobsFiltering();

            b.MinWidth             = 147;
            b.MinHeight            = 147;
            b.CoupledSizeFiltering = true;
            processed = b.Apply((Bitmap)processed);

            HomogenityEdgeDetector h = new HomogenityEdgeDetector();

            processed = h.Apply((Bitmap)processed);

            pictureBox2.Image = processed;

            BlobCounterBase bc = new BlobCounter();

            bc.ProcessImage(processed);
            Blob[] blobs = bc.GetObjectsInformation();


            //5 cents 7 pieces 700-800 pixels
            //10 cents 11 pieces 801-1000 pixels
            //25 cents 28 pieces 1001-1200 pixels
            //1 peso 13 pieces 1200-1500 pixels
            //5 peso 5 pieces 1501-1700 pixels

            int paybcents = 0, tencents = 0, twenypaybcents = 0, wanpeso = 0, paybpeso = 0;

            foreach (Blob blob in blobs)
            {
                if (blob.Area >= 700 && blob.Area <= 800)
                {
                    paybcents++;
                }
                else if (blob.Area >= 801 && blob.Area <= 1000)
                {
                    tencents++;
                }
                else if (blob.Area >= 1001 && blob.Area <= 1200)
                {
                    twenypaybcents++;
                }
                else if (blob.Area >= 1200 && blob.Area <= 1500)
                {
                    wanpeso++;
                }
                else if (blob.Area >= 1501 && blob.Area <= 1700)
                {
                    paybpeso++;
                }
            }
            double paybcentsbalyo      = paybcents * 0.05;
            double tencentsbalyo       = tencents * 0.1;
            double twenypaybcentsbalyo = twenypaybcents * 0.25;
            double wanpesobalyo        = wanpeso * 1;
            double paybpesobalyo       = paybpeso * 5;

            double total = paybcentsbalyo + tencentsbalyo + twenypaybcentsbalyo + wanpesobalyo + paybpesobalyo;

            MessageBox.Show("5 cents: " + paybcents + " pieces value: " + paybcentsbalyo + "\n10 cents: " + tencents + " pieces value: " + tencentsbalyo + "\n25 cents: " + twenypaybcents + " pieces value:" + twenypaybcentsbalyo + "\n1 peso: " + wanpeso + " pieces value:" + wanpesobalyo + "\n5 peso: " + paybpeso + " pieces value:" + paybpesobalyo + "\nTotal Value: " + total);
        }