如何将高斯高通内核显示为位图?

时间:2018-08-12 11:30:14

标签: c# image-processing bitmap gaussian

如何将Gaussian High Pass kernel转换为位图图像以进行显示?

我尝试了以下功能:

  1. 双精度至整数

    public static Bitmap ToBitmap(Array2d<double> image, PixelFormat pixelFormat)
    {
        Array2d<double> imageCopy = image.Copy();
    
        int Width = imageCopy.Width;
        int Height = imageCopy.Height;
    
        Bitmap bitmap = new Bitmap(Width, Height, pixelFormat);
    
        for (int y = 0; y < Height; y++)
        {
            for (int x = 0; x < Width; x++)
            {
                double d = imageCopy[x, y];
    
                int iii = Convert.ToInt32(d*255.0);
    
                Color clr = Color.FromArgb(iii, iii, iii);
    
                bitmap.SetPixel(x, y, clr);
            }
        }
    
        return bitmap;
    }
    
  2. 对数拉伸

    public static Array2d<double> Stretch(Array2d<double> data)
    {
        int Width = data.Width;
        int Height = data.Height;
    
        Array2d<double> array2d = new Array2d<double>(Width, Height);
    
        for (int i = 0; i < Width; i++)
        {
            for (int j = 0; j < Height; j++)
            {
                array2d[i, j] = Math.Log(data[i, j] + 1);
            }
        }
    
        return array2d;
    }
    

它们都不起作用,因为它们给出以下异常:

  

“ System.ArgumentException”类型的未处理异常发生在   System.Drawing.dll

     

其他信息:值'133028503'对于'红色'无效。   “红色”应大于或等于0且小于或等于   255。

来自高斯内核的示例数据中的以下内容:

enter image description here

某些值太低而有些值太高,无法转换为0-255范围内的整数。

0 个答案:

没有答案