【问题标题】:How to convert input image to 3D image format如何将输入图像转换为 3D 图像格式
【发布时间】:2021-07-09 09:13:25
【问题描述】:

我正在尝试用 C 编写图像旋转代码。

 int width, height, channels;
 unsigned char *img = stbi_load("butterfly.jpg", &width, &height, &channels, 0);
    

我正在阅读所见的图像。我想将这些图像数据转换为 3D(行、列、通道)数组格式才能做到这一点:

if (Xprime >= 1 && Yprime >= 1 && Xprime <= height && Yprime <= width)
            {
                pixel = img[Xprime][Yprime];
        }
        returnedOutImage[i][j] = pixel;
    }

【问题讨论】:

    标签: c image-processing matrix rotation


    【解决方案1】:

    您可以将其转换为 VLA。 我假设像素按 y 排序,然后按 x 排序,最后按通道排序。

    unsigned char (*img3d)[width][channels] = (void*)img;
    

    现在您可以通过img3[y][x][c] 访问它。

    这样的转换是否违反了严格的别名规则。

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 2017-08-31
      • 2016-05-31
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 2019-11-27
      • 2021-06-17
      相关资源
      最近更新 更多