0
我想繪製並使用以下幾行將一些氣象數據保存到png圖像文件中。OCTAVE - ind2rgb:X必須是索引圖像
imag = data2image(flipud(vari'));
imag = gray2ind(imag);
imwrite(imag,colormap('jet'),'PSFC_RIO_im.png','png');
其中data2image
是一個自定義函數重新縮放數據是由圖像的功能可用。
function image = data2image(data)
HIGH = max(data(:));
LOW = min(data(:));
image = (data - LOW)/(HIGH-LOW);
end
不幸的是,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
其中線53是在上面的代碼中的imwrite
。這個錯誤對我來說絕對沒有意義,因爲使用gray2ind
函數將圖像轉換爲索引圖像。我還通過與imshow
作圖測試了這一點。
編輯 - 類IMAG的:
octave:9> class(imag)
ans = double
似乎在Matlab R2012b中沒問題。你可以嘗試將你的變量名從'imag'和'image'改爲別的。兩者都是常見的內建函數的名稱。 – horchler
「imag」的類/數據類型是什麼? – Shai
@Shai,我該如何檢查數據類型? – jhc