簡體   English   中英

在GUIDE中編輯一個功能,是否更改所有功能?

[英]Editing one function in GUIDE, changes all functions?

我第一次使用Matlab的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 paint或ImageJ中打開它們時,它們才是灰度的。

每次進行GUI時,最好顯式指定父句柄。 例如:

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

axis(handles.ax1, 'on')

對於圖像和顏色圖,您應該了解MATLAB支持的圖像類型 (索引與Truecolor)。 還要注意,盡管有一些技術可以克服一個問題,但一個圖形僅將一個顏色圖應用於所有圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM