【问题标题】:EmguCv: Reduce the grayscalesEmguCv:降低灰度
【发布时间】:2015-01-03 19:30:04
【问题描述】:

有没有办法在openCv中降低灰度图像的灰度?

通常我有一个从 0 到 256 的灰度值

Image<Gray, byte> inputImage.

在我的情况下,我只需要 0-10 的灰度值。我有没有使用 OpenCV 的好方法,尤其是对于 C#?

【问题讨论】:

    标签: c# opencv image-processing grayscale


    【解决方案1】:

    OpenCV 上没有任何内置功能允许这种事情。

    不过,你可以自己写一些东西。看看这个C++ implementation 并把它翻译成C#:

    void colorReduce(cv::Mat& image, int div=64)
    {    
        int nl = image.rows;                    // number of lines
        int nc = image.cols * image.channels(); // number of elements per line
    
        for (int j = 0; j < nl; j++)
        {
            // get the address of row j
            uchar* data = image.ptr<uchar>(j);
    
            for (int i = 0; i < nc; i++)
            {
                // process each pixel
                data[i] = data[i] / div * div + div / 2;
            }
        }
    }
    

    只需将灰度Mat发送到此函数并使用div参数即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-06
      • 2011-02-26
      • 2020-10-03
      • 2013-07-18
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多