简体   繁体   English

用简单的opengl图像库(SOIL)加载图像(颜色空间:灰色)

[英]loading with simple opengl image library(SOIL) an image(color space: GRAY)

I want to read out the pixel values of an grey scale image. 我想读出灰度图像的像素值。 With RGB images I have no problems. 使用RGB图像我没有问题。 The code is just simply: 代码很简单:

int width, height;
unsigned char* image = SOIL_load_image(filepath.c_str(), &width, &height, 0, SOIL_LOAD_RGB);
std::cout << "size of image : " << size  << " width: " << width << " height: " << height << std::endl;

Now I want to load an image(png) with color space GRAY, I thought I could simply change SOIL_LOAD_RGB to SOIL_LOAD_L but that don't work out. 现在我想加载一个带有颜色空间GRAY的图像(png),我想我可以简单地将SOIL_LOAD_RGB更改为SOIL_LOAD_L,但这样做无法解决。

My output on the console is: size of image : -237407992 width: 10 height: -1312230988 我在控制台上的输出是:图像大小:-237407992宽度:10高度:-1312230988

And it is not constant. 它并不是一成不变的。 Only the width stays 10, and the height is changing every time I run the program. 只有宽度保持10,每次运行程序时高度都会改变。

Is there something I have to change or consider when working with gray scale images? 在处理灰度图像时,我有什么需要改变或考虑的吗?

您应该将第三个参数从“0”更改为“&channel”,如下所示

unsigned char *image = SOIL_load_image(filepath.c_str(), &width, &height, &channel, SOIL_LOAD_L);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM