2016-08-05 6 views
-1

をinsertshape機能を使用して行を挿入した後に凡例を追加:私は画像ビューアアプリを使用して挿入した円からの私のx、y座標を取ってい私のコードは次のようになりMathWorks社のMATLABで

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'); 

、それは右ではありません座標を一緒に共生させる方法。

+0

'legend'は' plot'、 'scatter'などとしか動作しないと思います。[' annotation']を使って必要な場所に文字列を書き込もうとします(http:// www。 mathworks.com/help/matlab/ref/annotation.html)を「凡例」の代わりに使用してください! –

+0

つまり、 'legend'には' axes'オブジェクトが必要です。 – EBH

答えて

0

insertShapeは、画像のRGBデータを直接変更し、挿入される図形のグラフィックスオブジェクトを生成しません。彼らは、1つの回避策として、the valid object types for legend

を、あなたはあなたの図形の各ダミーラインシリーズを生成することができNaN値はMATLABで視覚的にレンダリングされませんので:。このため、何のグラフィックスは(も参照表示するlegendのハンドルはありませんあなたの軸に表示されていないラインオブジェクトを作成するために使用することができる。例えば

:。

% 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) 

次生成

+0

あなたのコメントのおかげで、私は2行で2つの円を接続する必要があり、私は両方のためのxとyの座標を持って、どのように私はそれを使用して注釈を行う:line1 = [494,286,561,235]; 2行目= [580,228,672,197]と私はそれを試してみました。私はannotationを使う必要はありません。 – Kira

+0

@Kira既に行っているように 'insertShape'を使用してください。私はComputer Vision Toolboxを持っていないので、 '注釈 'だけを使用しました。 – excaza

+0

@Kiraわかりやすく私の例を更新しました。 – excaza

関連する問題