在GUIDE中编辑一个功能,改变所有功能?
问题描述:
我第一次使用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。
答
无论何时你正在做GUI的东西,最好明确指定父句柄。例如:
imshow(img, 'Parent',handles.ax1)
和
axis(handles.ax1, 'on')
至于图像和色彩映射表,你应该了解type of images MATLAB支持(索引与真彩色)。还要注意,一个人物只有一个色彩地图适用于所有图像,尽管有techniques至overcome this。
+0
真棒,非常感谢快速回复!这回答了我所有的问题。再次感谢! – Shinobii 2012-07-24 16:32:53
阅读MATLAB中的图像('img = imread('...')'),并为这两个图像发布'size(img)'和'class(img)'的输出 – Amro 2012-07-24 16:24:47