Example #1
0
        //TODO: podpiac ta funkcje do slidera gdzie bedzie ustawialo sie prog binaryzacji, blad chyba mozna ustawic programowo
        public Bitmap MeanInterativSelectionBinarization(Bitmap image)
        {
            // create filter
            IterativeThreshold filter = new IterativeThreshold(2, 128);
            // apply the filter
            Bitmap newImage = filter.Apply(image);

            return(newImage);
        }
Example #2
0
        public Bitmap BinarizacionIterativa()
        {
            Atributos atr = Atributos.getInstance();

            IterativeThreshold it = new IterativeThreshold(2, (byte)atr.umbralBinarizacion);

            imagen = it.Apply(imagen);
            umbral = it.ThresholdValue;
            return(imagen);
        }
        /// <summary>
        /// Binarize image with iterative threshold filter
        /// </summary>
        /// <param name="image"></param>
        /// <param name="threshold">threshold for binarization</param>
        public static Image IterativeThreshold(this Bitmap image, byte threshold)
        {
            if (image.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new NotSupportedException("Filter can be applied to binary 8bpp images only");
            }

            IterativeThreshold thresholdFilter = new IterativeThreshold(2, threshold);

            return(thresholdFilter.Apply(image));
        }
Example #4
0
        public mThresholdIterative(int thresholdValue, int minError)
        {
            ThresholdValue = thresholdValue;
            MinError       = minError;

            BitmapType = BitmapTypes.GrayscaleBT709;

            Effect = new IterativeThreshold(ThresholdValue, MinError);

            filter = Effect;
        }
Example #5
0
        private void imageLoad_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog
            {
                Filter = "Pliki graficzne|*.bmp; *.png; *.jpg; *.gif; *.jpeg"
            };
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                Bitmap    b         = new Bitmap(dlg.FileName);
                Grayscale filterG   = new Grayscale(0.2125, 0.7154, 0.0721);
                Bitmap    grayImage = b;
                if (b.PixelFormat != PixelFormat.Format8bppIndexed)
                {
                    grayImage = filterG.Apply(b);
                    IterativeThreshold filter = new IterativeThreshold(2, 128);
                    filter.ApplyInPlace(grayImage);
                }
                image.Source = BitmapToImageSource(grayImage);

                var path      = Path.GetDirectoryName(dlg.FileName);
                var filename  = Path.GetFileNameWithoutExtension(dlg.FileName);
                var extension = Path.GetExtension(dlg.FileName);
                imageFileName = new string[] { path, filename, extension };

                Bitmap[] shares = null;

                if (twoPixels.IsChecked == true)
                {
                    shares = twoPixelsF(grayImage);
                }
                else if (fourPixels.IsChecked == true)
                {
                    shares = fourPixelsF(grayImage);
                }
                else
                {
                    showAlert("Nieoczekiwany błąd. Pole obok nie zostało zaznaczone.");
                }
                showAlert("Udziały zostały automatycznie zapisane w folderze: " + imageFileName[0]);
                if (shares != null)
                {
                    firstShare.Source  = BitmapToImageSource(shares[0]);
                    secondShare.Source = BitmapToImageSource(shares[1]);
                }
            }
        }
        private System.Drawing.Rectangle?FindHealthbarRect()
        {
            var healthArea = CaptureApexWindow();
            // locating objects
            var blobCounter = new BlobCounter();

            blobCounter.CoupledSizeFiltering = true;
            blobCounter.FilterBlobs          = true;
            blobCounter.MinHeight            = 6;
            blobCounter.MinWidth             = 100;
            blobCounter.MaxHeight            = 15;

            //grayscale
            var bmp = Grayscale.CommonAlgorithms.BT709.Apply(healthArea);
            //Invert invert = new Invert();
            //bmp = invert.Apply(bmp);

            var filter = new IterativeThreshold(2, 4);

            // apply the filter
            filter.ApplyInPlace(bmp);
            blobCounter.ProcessImage(bmp);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            // check for rectangles
            var shapeChecker = new SimpleShapeChecker();

            shapeChecker.AngleError  = 5.0f;
            shapeChecker.LengthError = 0.5f;

            foreach (var blob in blobs)
            {
                List <AForge.IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blob);
                List <AForge.IntPoint> cornerPoints;

                try
                {
                    // use the shape checker to extract the corner points
                    if (shapeChecker.IsQuadrilateral(edgePoints, out cornerPoints))
                    {
                        PolygonSubType subType = shapeChecker.CheckPolygonSubType(cornerPoints);
                        if (subType == PolygonSubType.Trapezoid)
                        {
                            // here i use the graphics class to draw an overlay, but you
                            // could also just use the cornerPoints list to calculate your
                            // x, y, width, height values.
                            List <System.Drawing.Point> Points = new List <System.Drawing.Point>();
                            foreach (var point in cornerPoints)
                            {
                                Points.Add(new System.Drawing.Point(point.X, point.Y));
                            }
                            var boundingBox = GetBoundingBox(Points);
                            var ratio       = (boundingBox.Width / (float)boundingBox.Height);
                            if (ratio > 21.0f && ratio < 24.0f)
                            {
                                return(boundingBox);
                            }
                        }
                    }
                }
                catch (Exception e) { }
            }

            return(null);
        }