示例#1
0
        private ImageData32 Filter2D(FilterType type, ImageData32 src)
        {
            float[,] kernel = GetFilter(type);
            var dst     = new ImageData32(512, 512);
            int kernelW = kernel.GetLength(0);
            int kernelH = kernel.GetLength(1);
            int radius  = (kernelH - 1) / 2;

            for (int h = radius; h < src.Height - radius; h++)
            {
                for (int w = radius; w < src.Width - radius; w++)
                {
                    float sum = 0.0f;
                    for (int kH = h - radius, ky = 0; kH < h - radius + kernelH; kH++, ky++)
                    {
                        for (int kW = w - radius, kx = 0; kW < w - radius + kernelW; kW++, kx++)
                        {
                            sum += src.Data[kH * src.Width + kW] * kernel[ky, kx];
                        }
                    }
                    dst.Data[h * src.Width + w] = sum;
                }
            }
            return(dst);
        }
示例#2
0
        private BitmapSource CreateBitMapsource(ImageData32 image)
        {
            int          stride = image.Width * PixelFormats.Gray32Float.BitsPerPixel / 8;
            BitmapSource bitmap = BitmapSource.Create(512, 512, 96, 96, PixelFormats.Gray32Float, null, image.Data, stride);

            return(bitmap);
        }
示例#3
0
        public MediaSample()
        {
            InitializeComponent();

            this.imageData = new ImageData32(512, 512);
        }
示例#4
0
 private void Gaussian_Button_Click(object sender, RoutedEventArgs e)
 {
     this.imageData           = Filter2D(FilterType.Gauss, this.imageData);
     this.displayImage.Source = CreateBitMapsource(this.imageData);
 }
示例#5
0
 public ImageData32(ImageData32 data)
 {
     this.Data   = new float[data.Width * data.Height];
     this.Width  = data.Width;
     this.Height = data.Height;
 }