在GUIDE中编辑一个功能,更改所有功能?

时间:2012-07-24 16:03:08

标签: matlab image-processing matlab-guide

我第一次使用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中打开它们的时候。

1 个答案:

答案 0 :(得分:1)

在进行GUI操作时,最好明确指定父句柄。例如:

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

axis(handles.ax1, 'on')

对于图像和色彩映射,您应该了解type of images MATLAB支持(索引与真彩色)。另请注意,虽然有techniquesovercome this,但数字只有一个颜色图应用于所有图像。