简体   繁体   English

OCTAVE-ind2rgb:X必须是索引图像

[英]OCTAVE - ind2rgb: X must be an indexed image

I am trying to plot and save some meteorological data into png image files using the following lines. 我正在尝试使用以下几行将一些气象数据绘制并保存到png图像文件中。

imag = data2image(flipud(vari'));
imag = gray2ind(imag);
imwrite(imag,colormap('jet'),'PSFC_RIO_im.png','png');

where data2image is a custom function that re-scales the data to be usable by image functions. 其中data2image是自定义函数,可重新缩放图像功能以供图像函数使用。

function image = data2image(data)
    HIGH = max(data(:));
    LOW = min(data(:));
    image = (data - LOW)/(HIGH-LOW);
end

Unfortunately the imwrite complains with the following error: 不幸的是, imwrite抱怨以下错误:

error: ind2rgb: X must be an indexed image
error: called from:
error:   /usr/local/share/octave/3.6.4/m/image/ind2rgb.m at line 44, column 5
error:   /usr/local/share/octave/3.6.4/m/image/imwrite.m at line 176, column 16
error:   /home/tufts/Documents/Octave/geomat.m at line 53, column 1

Where line 53 is the imwrite in the code above. 第53行是上面代码中的imwrite This error makes absolutely no sense to me, as imag was converted to an indexed image with the gray2ind function. 这个错误对我来说毫无意义,因为imag已通过gray2ind函数转换为索引图像。 I also tested this by plotting with imshow , which works. 我还通过使用有效的imshow进行了测试。

EDIT - class of imag: 编辑-imag类:

octave:9> class(imag)
ans = double

I am going to answer my own question after accidentally, in an unrelated problem, figuring out how. 我将在一个不相关的问题中无意中回答我自己的问题,弄清楚如何做。

Indexed images in MATLAB have a minimum value of 1. My function was getting the minimum value of the data, and making that equal to 0. MATLAB中索引的图像的最小值为1。我的功能是获取数据的最小值,并将其等于0。

Take care of that, and you solve the problem 保重,就可以解决问题

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

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