2011-08-26 83 views
2

雖然使用Matlab的GUIDE,但我希望在圖像上繪製一條線。當我在GUI中只使用一個軸時,我設法實現了這一點。但是,在添加另一個軸時,繪圖不再覆蓋圖像。Matlab:在GUIDE中對圖像疊加繪圖

最初情節開始在錯誤的軸上繪圖,我意識到我忘記了設置適當的軸。但是,一旦我選擇了繪圖的圖像軸,要繪製的線條不再位於圖像的頂部,而只是用圖線替換圖像。

我的代碼:

imshow(img(k),'Parent',handles.display) 
hold on 

x1 = line(k).point1(1); 
y1 = line(k).point1(2); 
x2 = line(k).point2(1); 
y2 = line(k).point2(2); 
plot(handles.display,[x1 x2],[y1 y2],'Color','r','LineWidth', 2) 

hold off 

的代碼之前,我添加了新的軸線是相同的,但上面與handles.display參數爲plot()

任何幫助將不勝感激,謝謝你提前。

回答

1

當您調用HOLD函數時,還需要指定軸手柄。例如:

%# create some axes 
hAx1 = subplot(121); 
hAx2 = subplot(122); 

%# draw in first: image with line overlayed 
I = imread('coins.png'); 
imshow(I, 'Parent',hAx1) 
hold(hAx1,'on') 
plot(hAx1, [1 100], [1 100], 'Color','r', 'LineWidth',2) 
hold(hAx1,'off') 

%# draw in second 
surf(hAx2, peaks) 

enter image description here