使用Emgu CV获取和设置像素灰度图像 [英] Get and Set Pixel Gray scale image Using Emgu CV

查看:296
本文介绍了使用Emgu CV获取和设置像素灰度图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过将emgu Cv与C#结合使用来获取和设置灰度图像的像素。
如果我使用大图像,则会出现此错误消息:索引在数组的边界之外。

I am trying to get and set pixels of a gray scale image by using emgu Cv with C#. If I use a large image size this error message occurs: "Index was outside the bounds of the array."

如果我使用200x200或更小的图像,则没有错误,但我不明白为什么。

If I use an image 200x200 or less then there is no error but I don't understand why.

以下是我的代码:

 Image<Gray , byte> grayImage;
--------------------------------------------------------------------

        for (int v = 0; v < grayImage.Height; v++)
        {
            for (int u = 0; u < grayImage.Width; u++)
            {
                byte a = grayImage.Data[u , v , 0]; //Get Pixel Color | fast way
                byte b = (byte)(myHist[a] * (K - 1) / M);
                grayImage.Data[u , v , 0] = b; //Set Pixel Color | fast way
            }
        }
--------------------------------------------------------------------

http://i306.photobucket.com/albums/nn262/neji1909/9-6-25565-10-39.png

请帮助对不起,我的英语不好。

Please help me and sorry I am not good at English.

推荐答案

那是因为x和y在Data数组中是倒置的。您应该以这种方式更改代码(反转u和v):

That's because the x and y are inverted in the Data array. You should change your code this way (invert u and v):

    for (int v = 0; v < grayImage.Height; v++)
    {
        for (int u = 0; u < grayImage.Width; u++)
        {
            byte a = grayImage.Data[v , u , 0]; //Get Pixel Color | fast way
            byte b = (byte)(myHist[a] * (K - 1) / M);
            grayImage.Data[v , u , 0] = b; //Set Pixel Color | fast way
        }
    }

另请参见使用emgu cv迭代图像的像素

这篇关于使用Emgu CV获取和设置像素灰度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆