如何重置当前轴以在 MATLAB 中的相同轴上显示彩色或灰度图像?
How to reset the current axes to display either color or grayscale image on the same axes in MATLAB?
我有一些灰度图像,经过一些分割后,我将其中的一部分转换为彩色以供显示。
但是在同轴上显示灰度图像后,无法在轴上显示彩色图像。
例如:
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
,它仍然显示灰度图像而不是彩色图像。
谢谢,
果皮
% 根据图像类型在显示前设置颜色图
% --- 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,[])
我有一些灰度图像,经过一些分割后,我将其中的一部分转换为彩色以供显示。 但是在同轴上显示灰度图像后,无法在轴上显示彩色图像。
例如:
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
,它仍然显示灰度图像而不是彩色图像。
谢谢,
果皮
% 根据图像类型在显示前设置颜色图
% --- 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,[])