示例#1
0
        public int[,] Filter(int[,] pixels, ConvolutionMatrix matrix)
        {
            FilterBase filter = new ConvolutionFilter() { Matrix = matrix };
            int[,] result = filter.Execute(pixels);

            return result;
        }
示例#2
0
        protected override int OperateColors(int[,] pixelColors, ConvolutionMatrix matrix)
        {
            int rawRed = 0;
            int rawGreen = 0;
            int rawBlue = 0;

            for (int i = 0; i < matrix.Size; ++i)
            {
                for (int j = 0; j < matrix.Size; ++j)
                {
                    int color = pixelColors[i, j];
                    double coeff = matrix.Matrix[i, j];
                    rawRed += (int)(color.GetChannel(ChannelsFromARGBExtension.RED) * coeff);
                    rawGreen += (int)(color.GetChannel(ChannelsFromARGBExtension.GREEN) * coeff);
                    rawBlue += (int)(color.GetChannel(ChannelsFromARGBExtension.BLUE) * coeff);
                }
            }

            rawRed = CorrectResult(rawRed, Matrix.Factor, Matrix.Offset);
            rawGreen = CorrectResult(rawGreen, Matrix.Factor, Matrix.Offset);
            rawBlue = CorrectResult(rawBlue, Matrix.Factor, Matrix.Offset);

            int result = BuildColorFromChannels(rawRed, rawGreen, rawBlue);

            return result;
        }
示例#3
0
        public int[,] ApplySmooth(int[,] pixels, double weight = 2)
        {
            ConvolutionMatrix matrix = new ConvolutionMatrix(3);
            matrix.SetAll(1);
            matrix.Matrix[1, 1] = weight;
            matrix.Factor = weight + 8;

            FilterBase filter = new ConvolutionFilter() { Matrix = matrix };
            int[,] result = filter.Execute(pixels);

            return result;
        }
示例#4
0
        public int[,] Blur(int[,] pixels)
        {
            ConvolutionMatrix matrix = new ConvolutionMatrix(3);
            matrix.SetAll(2);
            matrix.Factor = 16;
            matrix.Offset = 0;

            matrix.Matrix[0, 0] = 1;
            matrix.Matrix[0, 2] = 1;
            matrix.Matrix[1, 1] = 4;
            matrix.Matrix[2, 0] = 1;
            matrix.Matrix[2, 2] = 1;

            return Filter(pixels, matrix);
        }
示例#5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pixelColor"></param>
 /// <param name="matrix"></param>
 /// <returns></returns>
 protected abstract int OperateColors(int[,] pixelColor, ConvolutionMatrix matrix);
示例#6
0
 public FilterBase(ConvolutionMatrix matrix)
 {
     Matrix = matrix;
 }
示例#7
0
 protected override int OperateColors(int[,] pixelColors, ConvolutionMatrix matrix)
 {
     return MinMaxColor(pixelColors);
 }