2013-07-15 42 views
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 
+1

似乎在Matlab R2012b中沒問題。你可以嘗試將你的變量名從'imag'和'image'改爲別的。兩者都是常見的內建函數的名稱。 – horchler

+0

「imag」的類/數據類型是什麼? – Shai

+0

@Shai,我該如何檢查數據類型? – jhc

回答

0

我要回答我的問題後,不小心,在一個不相關的問題,找出如何。在MATLAB

索引圖像有1.我的函數獲取數據的最小值,並使這等於0

採取照顧的最小值,並且你解決問題

相關問題