2012-07-24 172 views
0

我第一次使用Matlab的GUIDE,我試圖編輯兩個按鈕功能之一(都打開一個圖像),但編輯一個更改所有這些功能。下面是一些代碼:在GUIDE中編輯一個功能,改變所有功能?

% --- Executes on button press in Floating. 
function Floating_Callback(hObject, eventdata, handles) 

clc; 
axes(handles.axes1); 
[Float, PathName, FilterIndex] = uigetfile('*.bmp'); 
if(Float ~= 0) 
    Floating = fullfile(PathName, Float); 
    FloatArray = imread(Floating); 
    imshow(FloatArray); 
    axis on; 
end 

% Update handles structure 
guidata(hObject, handles); 

% hObject handle to Floating (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 


% --- Executes on button press in Reference. 
function Reference_Callback(hObject, eventdata, handles) 

clc; 
axes(handles.axes2); 
[Ref, PathName, FilterIndex] = uigetfile('*.bmp'); 
if(Ref ~= 0) 
    Reference = fullfile(PathName, Ref); 
    ReferenceArray = imread(Reference); 
    image(ReferenceArray); 
end 

% Update handles structure 
guidata(hObject, handles); 

例如,

image(ReferenceArray) 

將打開RBG的圖像,但

imshow(FloatArray) 

將在灰度打開(我也不明白爲什麼那是)。但我主要關注的是開放後

imshow(FloatArray) 

其他圖像會自動變成灰度。我很困惑...另外,據我所知,圖像已經灰度,至少他們是當我打開他們在MS油漆或ImageJ。

+0

閱讀MATLAB中的圖像('img = imread('...')'),併爲這兩個圖像發佈'size(img)'和'class(img)'的輸出 – Amro 2012-07-24 16:24:47

回答

1

無論何時你正在做GUI的東西,最好明確指定父句柄。例如:

imshow(img, 'Parent',handles.ax1) 

axis(handles.ax1, 'on') 

至於圖像和色彩映射表,你應該瞭解type of images MATLAB支持(索引與真彩色)。還要注意,一個人物只有一個色彩地圖適用於所有圖像,儘管有techniquesovercome this

+0

真棒,非常感謝快速回復!這回答了我所有的問題。再次感謝! – Shinobii 2012-07-24 16:32:53