Get and Set Pixel Gray scale image Using Emgu CV

百般思念 提交于 2019-12-04 15:12:38
rold2007

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
        }
    }

See also Iterate over pixels of an image with emgu cv

you are not indexing by (x,y) but by (row, col) - inverted. When you used 200x200 image it was the same whether you used width or height.

you could do that by using pointers (much faster) because if you are using indexing EmguCV internally uses calls to opencv for an every pixel.

so:

byte* ptr = (byte*)image.MIplImage.imageData;
int stride = image.MIplImage.widthStep;

int width = image.Width;
int height = image.Height;

for(int j = 0; j < height; j++) 
{
  for(int i = 0; i < width; i++)
  {
     ptr[i] = (byte)(myHist[a] * (K - 1) / M);
  }

  ptr += stride;
} 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!