如何重置当前轴以在MATLAB中的相同轴上显示彩色或灰度图像?

时间:2017-07-07 07:32:28

标签: matlab matlab-figure matlab-guide

我有一些灰度图像,经过一些分割后,我将一个部分转换为颜色以供显示。 但是,在同一轴上显示灰度图像后,我无法在轴上显示彩色图像。

例如:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global imB
global imF
global finalSegment_LE
i=38;
%         imB = img2{i} ;% Background original image
tempSeg = finalSegment_LE{i};
tempSeg(finalSegment_LE{i} ==0) = min(finalSegment_LE{i}(:));
imF = tempSeg;
cla(handles.axes1,'reset');
[~,~] = imoverlay(imB,imF,[],[],'hsv',0.8,handles.axes1); % color image..


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% global imB
temp = imread('cameraman.tif');
cla(handles.axes1,'reset');
axes(handles.axes1);
imshow(temp,[]) % grayscale image...

如果我先按pushbutton1我会看到彩色图像,但在按pushbutton2后,轴会变为灰度,即使按下pushbutton1,它仍会显示灰度图像而不是彩色图像。

谢谢,

戈皮

1 个答案:

答案 0 :(得分:0)

%基于图像类型

显示前设置色彩映射
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[img,cmap] = imread('peppers.png');
cla(handles.axes1,'reset');
colormap(handles.axes1,cmap);
axes(handles.axes1);
imshow(img,[]);


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% global imB
temp = imread('cameraman.tif');
cla(handles.axes1,'reset');
colormap(handles.axes1,gray);
axes(handles.axes1);
imshow(temp,[])