Beispiel #1
0
        private void ApplyFilter(ConvolutionBase2D kernel)
        {
            // Convert the original image to grayscale
            Convolution2D image = GetOriginalImageGrays();

            if (image == null)
            {
                // The original image is empty
                return;
            }

            Convolution2D filtered = null;

            if (kernel is Convolution2D)
            {
                #region Single

                Convolution2D kernelSingle = (Convolution2D)kernel;

                // This window builds kernels without gain or iterations, so make a clone with those tacked on
                Convolution2D kernelFinal = new Convolution2D(
                    kernelSingle.Values,
                    kernelSingle.Width,
                    kernelSingle.Height,
                    kernelSingle.IsNegPos,
                    trkGain.Value,
                    Convert.ToInt32(trkIterations.Value),
                    chkExpandBorder.IsChecked.Value);

                filtered = Convolutions.Convolute(image, kernelFinal);

                if (chkSubtract.IsChecked.Value)
                {
                    filtered = Convolutions.Subtract(image, filtered);
                }

                #endregion
            }
            else if (kernel is ConvolutionSet2D)
            {
                #region Set

                ConvolutionSet2D kernelSet = (ConvolutionSet2D)kernel;

                filtered = Convolutions.Convolute(image, kernelSet);

                #endregion
            }
            else
            {
                throw new ArgumentException("Unknown type of kernel: " + kernel.GetType().ToString());
            }

            // Show Filtered
            modifiedImage.Source = Convolutions.GetBitmap(filtered, (ConvolutionResultNegPosColoring)cboEdgeColors.SelectedValue);
        }