2016-08-05 63 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