2016-08-05 66 views
-1

我的代碼如下所示:加入傳奇

p = imread('C.png'); 
p1 = im2double(p); 
RG = insertShape(p1, 'Filledcircle', pos1, 'LineWidth', 10,'Color','blue','Opacity',1); 
RG = insertShape(RG, 'Line', {line1,line2},'Color',{0 1 0;0 1 1}); 
hc = imshow(RG); 
legend(hc,'line1','line2'); 
legend('show'); 

我把我的X和Y從我一直在使用圖片瀏覽器應用程序插入圓座標,是不正確的方法來獲得座標以將它們融合在一起。

+0

我不確定,但我覺得'legend'只能和'plot','scatter'等一起使用。試着用['annotation'](http:// www。 mathworks.com/help/matlab/ref/annotation.html)作爲'legend'的替代! –

+0

換句話說,'legend'可能需要一個'axes'對象來關聯。 – EBH

回答

0

insertShape直接修改圖像的RGB數據,不會爲插入的圖形生成圖形對象。正因爲如此,有沒有圖形處理爲legend顯示(見:the valid object types for legend

作爲一個解決方法,您可以生成每個形狀的虛擬線系列由於NaN值不受MATLAB視覺呈現,他們可用於創建,這不是你的軸顯示的行對象

例如:

% Read sample image 
RGB = imread('peppers.png'); 
imshow(RGB); 

% Add some annotations 
dim1 = [0.3 0.7 0.2 0.2]; 
annotation('rectangle', dim1, 'Color', 'red') 
dim2 = [0.6 0.5 0.1 0.1]; 
annotation('rectangle', dim2, 'Color', 'blue') 
x1 = [0.5 0.6]; 
y1 = [0.7 0.5]; 
annotation('line', x1, y1, 'Color', 'green', 'LineWidth', 2) 
x2 = [0.5 0.7]; 
y2 = [0.9 0.6]; 
annotation('line', x2, y2, 'Color', 'magenta', 'LineWidth', 2) 

% ============== EVERYTHING ABOVE THIS LINE IS SPECIFIC TO MY EXAMPLE, IGNORE IT 

% Plot dummy lineseries for legend 
% Specify 'DisplayName' for legend, can also be done manually in legend call 
hold on 
tmp(1) = plot(NaN, 'Color', 'green', 'LineWidth', 2, 'DisplayName', 'Green Line'); 
tmp(2) = plot(NaN, 'Color', 'magenta', 'LineWidth', 2, 'DisplayName', 'Magenta Line'); 
hold off 

% Display legend 
legend(tmp) 

將會產生如下:

yay

+0

感謝您的評論,我需要連接2個圈2線,我有兩個x和y座標,我如何使用註釋:line1 = [494,286,561,235];第2行= [580,228,672,197],我試過它似乎不適用於我使用註釋 – Kira

+0

@Kira你不需要使用'annotation'。使用'insertShape'就像你已經做的那樣。我只使用'annotation',因爲我沒有計算機視覺工具箱。 – excaza

+0

@Kira爲了清晰起見,我更新了示例。 – excaza