首页 > 解决方案 > 如何将高斯高通内核显示为位图?

问题描述

如何将高斯高通内核转换为位图图像以供显示?

我尝试了以下功能:

  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.Drawing.dll 中出现“System.ArgumentException”类型的未处理异常

附加信息:“133028503”的值对“红色”无效。'red' 应大于或等于 0 且小于或等于 255。

以下来自高斯核的样本数据:

在此处输入图像描述

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

标签: c#image-processingbitmapgaussian

解决方案


推荐阅读