2017-07-07 71 views
0

我有一些灰度圖像,經過一些細分處理後,我將部分轉換爲彩色以用於顯示目的。 但在同一軸上顯示灰度圖像後,我無法在軸上顯示彩色圖像。如何重置當前軸以在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,它仍然顯示灰度圖像,而不是彩色圖像。

謝謝,

戈皮顯示基於圖像類型之前

回答

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,[])