コード例 #1
0
        private void SetKernel(PresetKernel kernel)
        {
            this.Size = 5; //call setter, so all other calculations are made
            #region Preset Convolution Kernels
            switch (kernel)
            {
            case PresetKernel.Identity:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0 },
                    { 0, 0, 1, 0, 0 },
                    { 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.Blur:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, 1, 2, 1, 0 },
                    { 0, 2, 2, 2, 0 },
                    { 0, 1, 2, 1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 14.0;
                break;

            case PresetKernel.BlurMore:
                _kernel = new double[5, 5]
                {
                    { 0, 1, 1, 1, 0 },
                    { 1, 2, 2, 2, 1 },
                    { 1, 2, 4, 2, 1 },
                    { 1, 2, 2, 2, 1 },
                    { 0, 1, 1, 1, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 32.0;
                break;

            case PresetKernel.ColoredEmboss:
                _kernel = new double[5, 5]
                {
                    { -20, 0, 0, 0, -10 },
                    { 0, -20, 10, -20, 0 },
                    { 0, 10, 35, 10, 0 },
                    { 0, -20, 10, 20, 0 },
                    { -20, 0, 0, 0, 10 }
                };
                _bias = 80.0;
                _normalizationFactor = 10.0;
                break;

            case PresetKernel.DoubleVision:
                _kernel = new double[5, 5]
                {
                    { -1, -2, -1, -2, -1 },
                    { 2, -1, 2, -1, 2 },
                    { -1, -2, 5, -2, -1 },
                    { 2, -1, 2, -1, 2 },
                    { -1, -2, -1, -2, -1 }
                };
                _bias = 0.0;
                _normalizationFactor = -7.0;
                break;

            case PresetKernel.Emboss:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, 1, 1, 1, 0 },
                    { 0, 1, -1, -1, 0 },
                    { 0, 1, -1, -1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.FindEdges:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, -1, -1, -1, 0 },
                    { 0, -1, 8, -1, 0 },
                    { 0, -1, -1, -1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.Grease:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, 1, 1, 1, 0 },
                    { 0, 1, -7, 1, 0 },
                    { 0, 1, 1, 1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.HiPass:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, 1, -2, 1, 0 },
                    { 0, -2, 6, -2, 0 },
                    { 0, 1, -2, 1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 2.0;
                break;

            case PresetKernel.HiPassSharpen:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, 0, -1, 0, 0 },
                    { 0, -1, 5, -1, 0 },
                    { 0, 0, -1, 0, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.HorizontalEdge:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, -1, -1, -1, 0 },
                    { 0, 0, 0, 0, 0 },
                    { 0, 1, 1, 1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.HorizontalSobel:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, -1, -2, -1, 0 },
                    { 0, 0, 0, 0, 0 },
                    { 0, 1, 2, 1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.Laplace:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, 0, -1, 0, 0 },
                    { 0, -1, 4, -1, 0 },
                    { 0, 0, -1, 0, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.Mean:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, 1, 1, 1, 0 },
                    { 0, 1, 1, 1, 0 },
                    { 0, 1, 1, 1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 9.0;
                break;

            case PresetKernel.MeanRemoval:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, -1, -1, -1, 0 },
                    { 0, -1, 9, -1, 0 },
                    { 0, -1, -1, -1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.Smooth:

                break;

            case PresetKernel.SmoothCircular:
                _kernel = new double[5, 5]
                {
                    { 0, 1, 1, 1, 0 },
                    { 1, 1, 1, 1, 1 },
                    { 1, 1, 1, 1, 1 },
                    { 1, 1, 1, 1, 1 },
                    { 0, 1, 1, 1, 0 }
                };
                _bias = 0.0;
                _normalizationFactor = 21.0;
                break;

            case PresetKernel.SmoothMore:
                break;

            case PresetKernel.TraceContour:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, -1, -1, -1, 0 },
                    { 0, -1, 9, -1, 0 },
                    { 0, -1, -1, -1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 255.0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.VerticalEdge:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, -1, 0, 1, 0 },
                    { 0, -1, 0, 1, 0 },
                    { 0, -1, 0, 1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.VerticalSobel:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 0, 0, 0 },
                    { 0, -1, 0, 1, 0 },
                    { 0, -2, 0, 2, 0 },
                    { 0, -1, 0, 1, 0 },
                    { 0, 0, 0, 0, 0 }
                };
                _bias = 0;
                _normalizationFactor = 1.0;
                break;

            case PresetKernel.Vibrate:
                _kernel = new double[5, 5]
                {
                    { 9, 0, 3, 0, 9 },
                    { 0, 0, 0, 0, 0 },
                    { 3, 0, 1, 0, 3 },
                    { 0, 0, 0, 0, 0 },
                    { 9, 0, 3, 0, 9 }
                };
                _bias = 0;
                _normalizationFactor = 49.0;
                break;

            case PresetKernel.LaplacianOfGaussian:
                _kernel = new double[5, 5]
                {
                    { 0, 0, 1, 0, 0 },
                    { 0, 1, 2, 1, 0 },
                    { 1, 2, -16, 2, 1 },
                    { 0, 1, 2, 1, 0 },
                    { 0, 0, 1, 0, 0 }
                };
                _bias = 0;
                _normalizationFactor = 1.0;
                break;

            default:
                break;
            }
            #endregion
        }
コード例 #2
0
 public ConvolutionKernel(PresetKernel kernel)
 {
     SetKernel(kernel);
 }