Exemplo n.º 1
0
 public static void SetAdaptTreshold(IplImage gray, ref IplImage threshold, AdaptiveThresholdType aptTValue, ThresholdType thsType, double ThresholdValue, int AdaptativeVal1, int AdaptativeVal2)
 {
     try
     {
         gray.AdaptiveThreshold(threshold, ThresholdValue, aptTValue, thsType, AdaptativeVal1, AdaptativeVal1);
     }
     catch (Exception e)
     {
         MainWindow.Instance.OpenDialog("Invalid value combination", e.Message);
     }
 }
        public static Image <Gray, byte> AdaptiveThreshold
        (
            this Image <Gray, byte> inImage
            , double maxVal = 250
            , AdaptiveThresholdType adaptiveThresholdType = AdaptiveThresholdType.MeanC
            , ThresholdType thresholdType = ThresholdType.BinaryInv
            , int blockSize = 39
            , double param1 = 4)
        {
            var outImage = inImage.Copy();

            CvInvoke.AdaptiveThreshold
                (GaussBlur(inImage), outImage, maxVal, adaptiveThresholdType, thresholdType, blockSize, param1);
            return(outImage);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="thresholdType">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="blockSize">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
        /// <param name="param1">各適応手法に応じたパラメータ. 適応手法がMeanCおよびGaussianCの場合は,平均値または重み付き平均値から引く定数. 負の値の場合もある.</param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
        /// <param name="thresholdType">Thresholding type.</param>
        /// <param name="blockSize">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
        /// <param name="param1">The method-dependent parameter. For the methods MeanC and GaussianC it is a constant subtracted from mean or weighted mean (see the discussion), though it may be negative. </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize, double param1)
        {
            if (src == null)
            {
                throw new ArgumentNullException("src");
            }
            if (dst == null)
            {
                throw new ArgumentNullException("dst");
            }

            if (thresholdType != ThresholdType.Binary && thresholdType != ThresholdType.BinaryInv)
            {
                throw new ArgumentException("thresholdType == Binary || thresholdType == BinaryInv");
            }
            NativeMethods.cvAdaptiveThreshold(src.CvPtr, dst.CvPtr, maxValue, adaptiveMethod, thresholdType, blockSize, param1);
        }
Exemplo n.º 4
0
        private void comboAdaptiveThresholdType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (useAdaptive)
            {
                switch (comboAdaptiveThresholdType.SelectedIndex)
                {
                case (int)AdaptiveThresholdType.MeanC:
                    _adaptiveThresholdType = AdaptiveThresholdType.MeanC;
                    break;

                case (int)AdaptiveThresholdType.GaussianC:
                    _adaptiveThresholdType = AdaptiveThresholdType.GaussianC;
                    break;

                default:
                    break;
                }
                buttonBinarisation_Click(sender, e);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Applies an adaptive threshold to an array.
 /// Source matrix must be 8-bit single-channel image.
 /// </summary>
 /// <param name="maxValue">Non-zero value assigned to the pixels for which the condition is satisfied. See the details below.</param>
 /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use, ADAPTIVE_THRESH_MEAN_C or ADAPTIVE_THRESH_GAUSSIAN_C .</param>
 /// <param name="thresholdType">Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV .</param>
 /// <param name="blockSize">Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.</param>
 /// <param name="c">Constant subtracted from the mean or weighted mean (see the details below). 
 /// Normally, it is positive but may be zero or negative as well.</param>
 /// <returns>Destination image of the same size and the same type as src.</returns>
 public Mat AdaptiveThreshold(double maxValue, AdaptiveThresholdType adaptiveMethod, 
     ThresholdType thresholdType, int blockSize, double c)
 {
     var dst = new Mat();
     Cv2.AdaptiveThreshold(this, dst, maxValue, adaptiveMethod, 
         thresholdType, blockSize, c);
     return dst;
 }
Exemplo n.º 6
0
 public static extern void cvAdaptiveThreshold(IntPtr src, IntPtr dst, double max_value, AdaptiveThresholdType adaptiveType,
     ThresholdType threshold_type, int block_size, double param1);
Exemplo n.º 7
0
 /// <summary>
 /// Applies an adaptive threshold to an array.
 /// </summary>
 /// <param name="src">Source 8-bit single-channel image.</param>
 /// <param name="dst">Destination image of the same size and the same type as src .</param>
 /// <param name="maxValue">Non-zero value assigned to the pixels for which the condition is satisfied. See the details below.</param>
 /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use, ADAPTIVE_THRESH_MEAN_C or ADAPTIVE_THRESH_GAUSSIAN_C .</param>
 /// <param name="thresholdType">Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV .</param>
 /// <param name="blockSize">Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.</param>
 /// <param name="c">Constant subtracted from the mean or weighted mean (see the details below). 
 /// Normally, it is positive but may be zero or negative as well.</param>
 public static void AdaptiveThreshold(InputArray src, OutputArray dst,
     double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize, double c)
 {
     if (src == null)
         throw new ArgumentNullException("src");
     if (dst == null)
         throw new ArgumentNullException("dst");
     src.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     NativeMethods.imgproc_adaptiveThreshold(src.CvPtr, dst.CvPtr, maxValue, (int)adaptiveMethod, (int)thresholdType, blockSize, c);
     dst.Fix();
 }
Exemplo n.º 8
0
 public void AdaptiveThreshold(AdaptiveThresholdType adaptiveType = AdaptiveThresholdType.MeanC, ThresholdType thresholdType = ThresholdType.Binary, double maxValue = 255)
 {
     CvInvoke.AdaptiveThreshold(this.Data, this.Data, maxValue, adaptiveType, thresholdType, 201, -2);
 }
Exemplo n.º 9
0
        public Mat Quantize(Mat image)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var            sourceImage   = image;
            var            destImage     = new Mat(sourceImage.Size, DepthType.Default, 1);
            var            destImageBin  = new Mat(sourceImage.Size, DepthType.Default, 1);
            Matrix <float> srcKeypoints  = new Matrix <float>(_keypoints);
            Matrix <float> destKeypoints = new Matrix <float>(new float[, ] {
                { 0, 0 }, { GameBoyConstants.ScreenWidth, 0 }, { 0, GameBoyConstants.ScreenHeight }, { GameBoyConstants.ScreenWidth, GameBoyConstants.ScreenHeight }
            });

            // calculate transformation matrix
            var transform = CvInvoke.GetPerspectiveTransform(srcKeypoints, destKeypoints);

            _logger.Info($"{stopwatch.ElapsedMilliseconds} ms, GetPerspectiveTransform");
            stopwatch.Restart();

            /* Too resource-intensive!
             * // denoise
             * CvInvoke.FastNlMeansDenoising(sourceImage, sourceImage);
             *
             * _logger.Info($"{stopwatch.ElapsedMilliseconds} ms, FastNlMeansDenoising");
             * stopwatch.Restart();
             */

            // transform
            CvInvoke.WarpPerspective(sourceImage, destImage, transform, new Size(GameBoyConstants.ScreenWidth, GameBoyConstants.ScreenHeight), Inter.Linear, Warp.Default);

            _logger.Info($"{stopwatch.ElapsedMilliseconds} ms, WarpPerspective");
            stopwatch.Restart();

            // threshold
            CvInvoke.AdaptiveThreshold(destImage, destImageBin, 255, _mode, ThresholdType.Binary, _block, _c);

            _logger.Info($"{stopwatch.ElapsedMilliseconds} ms, AdaptiveThreshold");
            stopwatch.Restart();

            while (_adjust)
            {
                CvInvoke.AdaptiveThreshold(destImage, destImageBin, 255, _mode, ThresholdType.Binary, _block, _c);

                CvInvoke.NamedWindow("Test");
                CvInvoke.Imshow("Test", destImageBin);


                string outputFilename = "quantizer_output.png";
                string outputPath     = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), outputFilename);
                destImageBin.Save(outputPath);

                int key = CvInvoke.WaitKey();
                Debug.Write(key);
                if (key == 2490368)
                {
                    _block += 2;
                }
                if (key == 2621440)
                {
                    _block -= 2;
                }
                if (key == 2424832)
                {
                    _c++;
                }
                if (key == 2555904)
                {
                    _c--;
                }
                if (key == 109)
                {
                    _mode = AdaptiveThresholdType.MeanC;
                }
                if (key == 103)
                {
                    _mode = AdaptiveThresholdType.GaussianC;
                }
                if (key == 27)
                {
                    break;
                }

                if (_block < 3)
                {
                    _block = 3;
                }

                _logger.Info("Constant: " + _c);
                _logger.Info("Block size: " + _block);
                _logger.Info("Mode: " + _mode);
            }

            return(destImageBin);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="thresholdType">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="blockSize">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
        /// <param name="thresholdType">Thresholding type.</param>
        /// <param name="blockSize">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize)
        {
            AdaptiveThreshold(src, dst, maxValue, adaptiveMethod, thresholdType, blockSize, 5);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod)
        {
            AdaptiveThreshold(src, dst, maxValue, adaptiveMethod, ThresholdType.Binary, 3, 5);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="max_value">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptive_method">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="threshold_type">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="block_size">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
        /// <param name="param1">各適応手法に応じたパラメータ. 適応手法がMeanCおよびGaussianCの場合は,平均値または重み付き平均値から引く定数. 負の値の場合もある.</param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="max_value">Maximum value that is used with CV_THRESH_BINARY and CV_THRESH_BINARY_INV. </param>
        /// <param name="adaptive_method">Adaptive thresholding algorithm to use: CV_ADAPTIVE_THRESH_MEAN_C or CV_ADAPTIVE_THRESH_GAUSSIAN_C.</param>
        /// <param name="threshold_type">Thresholding type.</param>
        /// <param name="block_size">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
        /// <param name="param1">The method-dependent parameter. For the methods CV_ADAPTIVE_THRESH_MEAN_C and CV_ADAPTIVE_THRESH_GAUSSIAN_C it is a constant subtracted from mean or weighted mean (see the discussion), though it may be negative. </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double max_value, AdaptiveThresholdType adaptive_method, ThresholdType threshold_type, int block_size, double param1)
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (dst == null)
                throw new ArgumentNullException("dst");

            if (threshold_type != ThresholdType.Binary && threshold_type != ThresholdType.BinaryInv)
            {
                throw new ArgumentOutOfRangeException("閾値処理の種類は、BinaryかBinaryInvのどちらかである必要があります。");
            }
            CvInvoke.cvAdaptiveThreshold(src.CvPtr, dst.CvPtr, max_value, adaptive_method, threshold_type, block_size, param1);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="max_value">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptive_method">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="threshold_type">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="block_size">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="max_value">Maximum value that is used with CV_THRESH_BINARY and CV_THRESH_BINARY_INV. </param>
        /// <param name="adaptive_method">Adaptive thresholding algorithm to use: CV_ADAPTIVE_THRESH_MEAN_C or CV_ADAPTIVE_THRESH_GAUSSIAN_C.</param>
        /// <param name="threshold_type">Thresholding type.</param>
        /// <param name="block_size">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double max_value, AdaptiveThresholdType adaptive_method, ThresholdType threshold_type, Int32 block_size)
        {
            AdaptiveThreshold(src, dst, max_value, adaptive_method, threshold_type, block_size, 5);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod)
        {
            AdaptiveThreshold(src, dst, maxValue, adaptiveMethod, ThresholdType.Binary, 3, 5);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="thresholdType">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="blockSize">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
        /// <param name="param1">各適応手法に応じたパラメータ. 適応手法がMeanCおよびGaussianCの場合は,平均値または重み付き平均値から引く定数. 負の値の場合もある.</param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
        /// <param name="thresholdType">Thresholding type.</param>
        /// <param name="blockSize">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
        /// <param name="param1">The method-dependent parameter. For the methods MeanC and GaussianC it is a constant subtracted from mean or weighted mean (see the discussion), though it may be negative. </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize, double param1)
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (dst == null)
                throw new ArgumentNullException("dst");

            if (thresholdType != ThresholdType.Binary && thresholdType != ThresholdType.BinaryInv)
            {
                throw new ArgumentException("thresholdType == Binary || thresholdType == BinaryInv");
            }
            NativeMethods.cvAdaptiveThreshold(src.CvPtr, dst.CvPtr, maxValue, adaptiveMethod, thresholdType, blockSize, param1);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="thresholdType">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="blockSize">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
        /// <param name="thresholdType">Thresholding type.</param>
        /// <param name="blockSize">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize)
        {
            AdaptiveThreshold(src, dst, maxValue, adaptiveMethod, thresholdType, blockSize, 5);
        }
Exemplo n.º 17
0
        private void runFilterButton_Click(object sender, EventArgs e)
        {
            Bitmap             pBoxImage;
            Image <Bgr, byte>  inputImage;
            Image <Gray, Byte> grayImage;

            try
            {
                pBoxImage  = new Bitmap(pictureBox1.Image);
                inputImage = new Image <Bgr, Byte>(pBoxImage);
                grayImage  = inputImage.Convert <Gray, Byte>();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }

            switch (filtersComboBox.SelectedIndex)
            {
            case 0:             //Gaussian
                colorFlag            = true;
                filterLabel1.Visible = false;
                int otherGaussKernal = 5;
                if (otherGaussKernal % 2 == 0)
                {
                    gaussKernel--;
                    //textBox1.Text = otherGaussKernal.ToString();
                }
                inputImage._SmoothGaussian(otherGaussKernal);
                break;

            case 1:             //Histogram Equalization
                colorFlag = true;
                inputImage._EqualizeHist();
                break;

            case 2:             //MorphClose
                colorFlag = true;
                Mat kernel = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross, new Size(15, 15), new Point(1, 1));
                Emgu.CV.CvEnum.MorphOp operation = Emgu.CV.CvEnum.MorphOp.Close;
                Point anchor     = new Point(-1, -1);
                int   iterations = 1;
                Emgu.CV.CvEnum.BorderType   borderType  = Emgu.CV.CvEnum.BorderType.Default;
                Emgu.CV.Structure.MCvScalar borderValue = new MCvScalar();
                inputImage._MorphologyEx(operation, kernel, anchor, iterations, borderType, borderValue);
                break;

            case 3:             //MorphCloseB&W
                colorFlag = false;
                //Image<Gray, Byte> grayImage = inputImage.Convert<Gray, Byte>();
                Mat kernel1 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross, new Size(15, 15), new Point(1, 1));
                Emgu.CV.CvEnum.MorphOp operation1 = Emgu.CV.CvEnum.MorphOp.Close;
                Point anchor1     = new Point(-1, -1);
                int   iterations1 = 1;
                Emgu.CV.CvEnum.BorderType   borderType1  = Emgu.CV.CvEnum.BorderType.Default;
                Emgu.CV.Structure.MCvScalar borderValue1 = new MCvScalar();
                grayImage._MorphologyEx(operation1, kernel1, anchor1, iterations1, borderType1, borderValue1);
                break;

            case 4:             //Monochrome
                colorFlag = false;
                break;

            case 5:             //Canny
                colorFlag = false;
                double cannyThresh        = 10;
                double cannyThreshLinking = 500;
                grayImage = grayImage.Canny(cannyThresh, cannyThreshLinking);
                break;

            case 6:             //Laplace
                colorFlag = false;
                int laplaceApertureSize = 1;
                //grayImage = grayImage.Laplace(apertureSize);
                //grayImage.Laplace(apertureSize).ConvertFrom();
                Image <Gray, float> cannyGrayImageFloat = grayImage.Laplace(laplaceApertureSize);
                grayImage = cannyGrayImageFloat.Convert <Gray, Byte>();
                break;

            case 7:             //Sobel
                colorFlag = false;
                int sobelXOrder       = 1;
                int sobelYOrder       = 1;
                int sobelApertureSize = 5;
                Image <Gray, float> sobelGrayImageFloat = grayImage.Sobel(sobelXOrder, sobelYOrder, sobelApertureSize);
                grayImage = sobelGrayImageFloat.Convert <Gray, Byte>();
                break;

            case 8:             //SmoothBilatral
                colorFlag = true;
                int kernelSize = 25;
                int colorSigma = 55;
                int spaceSigma = 55;
                inputImage = inputImage.SmoothBilatral(kernelSize, colorSigma, spaceSigma);
                break;

            case 9:             //ThresholdAdaptive
                colorFlag = false;
                Emgu.CV.Structure.Gray maxValue      = new Gray(150);
                AdaptiveThresholdType  adaptiveType  = AdaptiveThresholdType.GaussianC;
                ThresholdType          thresholdType = ThresholdType.Binary;
                int blockSize = 3;
                Emgu.CV.Structure.Gray param1 = new Gray();
                grayImage = grayImage.ThresholdAdaptive(maxValue, adaptiveType, thresholdType, blockSize, param1);
                break;

            case 10:             //SmoothMedian
                colorFlag = true;
                int smoothMedianSize = 25;
                inputImage = inputImage.SmoothMedian(smoothMedianSize);
                break;

            case 11:             //CLAHE
                colorFlag = true;
                IInputArray CLAHEsrc          = inputImage.GetOutputArray();
                double      CLAHEClipLimit    = 40;
                Size        CLAHETileGridSize = new System.Drawing.Size(8, 8);
                OutputArray CLAHEdst;
                Emgu.CV.CvInvoke.CLAHE(CLAHEsrc, CLAHEClipLimit, CLAHETileGridSize, CLAHEdst);
                break;



            default:
                MessageBox.Show("No filter selected, or failure occured");
                break;
            }

            filterPictureBox.SizeMode = PictureBoxSizeMode.Zoom;
            if (colorFlag)
            {
                filterPictureBox.Image = inputImage.ToBitmap();
            }
            else
            {
                filterPictureBox.Image = grayImage.ToBitmap();
            }
        }