public static Convolution2D Convolute(Convolution2D image, ConvolutionBase2D kernel, string description = "")
 {
     if (kernel is Convolution2D)
     {
         return Convolute_Single(image, (Convolution2D)kernel, description);
     }
     else if (kernel is ConvolutionSet2D)
     {
         return Convolute_Set(image, (ConvolutionSet2D)kernel, description);
     }
     else
     {
         throw new ApplicationException("Unexpected type of kernel: " + kernel.GetType().ToString());
     }
 }
 public static Border GetThumbnail(ConvolutionBase2D conv, int thumbSize, ContextMenu contextMenu, ConvolutionToolTipType typeSet = ConvolutionToolTipType.None, ConvolutionToolTipType typeSingle = ConvolutionToolTipType.Size)
 {
     if (conv is Convolution2D)
     {
         return GetThumbnail_Single((Convolution2D)conv, thumbSize, contextMenu, typeSingle);
     }
     else if (conv is ConvolutionSet2D)
     {
         return GetThumbnail_Set((ConvolutionSet2D)conv, thumbSize, contextMenu, typeSet);
     }
     else
     {
         throw new ArgumentException("Unknown type of kernel: " + conv.GetType().ToString());
     }
 }
        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);
        }