【问题标题】:image processing (general)图像处理(一般)
【发布时间】:2011-11-28 09:35:45
【问题描述】:

抱歉,我提出了一个愚蠢的问题,但我是这方面的新手,我找不到答案。

  1. 什么是图像步幅?
  2. 我正在从位帧创建一个缓冲区字节[](没有问题。)位帧宽度为 1200,位帧高度为 900。所以(我怀疑)缓冲区必须为 1200*900 = 108,0000。 但是缓冲区大小是步幅 * 高度 = 432,0000 (4 * 108,0000)。

步幅计算为bitFrame.PixelWidth * ((bitFrame.Format.BitsPerPixel + 7) / 8); 然后我使用bitFrame.CopyPixels(pixels, stride, 0); //(byte[] pixels) 并且我有处理当前像素的功能(也就是一个结构体)

struct pixel {
    float r;
    float g;
    float b;
};

还有像素处理函数pixelprocessPixel(int x, int y)。我如何在缓冲区中使用此功能?我认为它必须以某种方式这样称呼:

for(int i = 0; i < height; i++) {
  for(int j = 0; j < height; j++) {
    processPixel(i, j); 
    // But how could I use this function with my byte[] buffer?
    // And what exactly in this buffer? 
    // (why stride*height = 4*width*height? cause there are 3 values for pixel RGB)
  }
}

【问题讨论】:

  • 我刚刚用谷歌搜索了“图像步幅”,第一次点击看起来不错,有什么具体的内容你找不到吗?
  • 谢谢。我刚找到这个/问题的第二部分呢?

标签: c# image-processing stride


【解决方案1】:

Stride 是每行像素的字节数,无论这些像素中有多少是图像的一部分,因此您必须使用 stride 根据二维坐标计算要影​​响的字节:

void processPixel(int x, int y)
{
    // This is if your image format is 4 bytes per pixel such as RGBA
    int startByteIndex = x * 4 + y * stride; 
}

编辑:我太着急了——根据 cmets 更新了答案。

【讨论】:

  • 您的代码与您的正确描述不符。它应该是 x * 4 + y * 步幅。
  • 感谢您的帮助/更正。我担心我可能没有足够勤奋地确保代码的正确性,但我希望如果有问题有人能纠正我。很高兴看到它如我所愿。
猜你喜欢
  • 2021-01-17
  • 2013-05-10
  • 1970-01-01
  • 1970-01-01
  • 2012-01-26
  • 2015-10-13
  • 2010-12-10
  • 2013-01-05
  • 1970-01-01
相关资源
最近更新 更多