简体   繁体   English

尝试在MATLAB中将x * y * 3矩阵转换为图像时出错?

[英]Error trying to convert x * y * 3 matrix to image in MATLAB?

I have an x*y*3 matrix in MATLAB which I'm trying to convert to an image (layer one is the R intensity, layer 2 is the G intensity, layer 3 is the B intensity. 我在MATLAB中有一个x * y * 3矩阵,试图将其转换为图像(第一层是R强度,第二层是G强度,第三层是B强度。

I'm currently only using an imwrite function to convert it, but the resulting image is always in black and white. 我目前仅使用imwrite函数将其转换,但是生成的图像始终为黑白图像。 Because my calculations all currently rely on the matrix being 3 layers I can't compress it down to one and use the ind2rgb function and the map, can I? 因为我的计算当前都依赖于3层矩阵,所以我无法将其压缩为1层并使用ind2rgb函数和地图,可以吗?

I'm pretty lost, so any advice would be greatly appreciated. 我很迷茫,因此任何建议将不胜感激。 Please and thank you! 谢谢,麻烦您了!

It is possible that the values of your image are out of range. 图片的值可能超出范围。

You can try either uint8() : 您可以尝试使用uint8()

imwrite(uint8(I), 'file.png');

or, mat2gray() : mat2gray()

imwrite(mat2gray(I),'file.png');

assuming I is your image data. 假设是你的图像数据。

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

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