Drawing two shapes on one image
3 ビュー (過去 30 日間)
古いコメントを表示
This is part of what I have done for drawing a shape on my images:
...
...
k = convhull(x,y);
I=imread('img.png');
imshow(I)
hold on
plot(x(k),y(k),'r-',x,y,'b+');
BW = roipoly(I, x(k), y(k) );
What should I do in order to receive the binary result as in BW, but that contains the other shape (i.e; xx, yy)?
I kept hold on, and was able to plot the second shape, but the issue was how to get the binary result of the two shapes at the image.
Thanks.
0 件のコメント
回答 (2 件)
Youssef Khmou
2013 年 12 月 23 日
編集済み: Youssef Khmou
2013 年 12 月 24 日
You can transform I into logical matrix first ( binary), then perform the other operations to add the shape after executing the command 'hold on', , here is an example :
I=imread('circuit.tif');
B=im2bw(I);
% example of drawing shape in the binary image B
% first shape.
p1=150+rand(100,1)*200;
p2=100+rand(100,1)*100;
% second shape.
p3=10+rand(100,1)*50;
p4=10+rand(100,1)*60;
k=convhull(p1,p2);
k2=convhull(p3,p4);
imshow(B), hold on, plot(p1(k),p2(k),'-r',p3(k2),p4(k2),'-g'), hold off;
2 件のコメント
Youssef Khmou
2013 年 12 月 24 日
you can try the edited code above, it it working fine, i hope you will explain better your situation it the edited code is not working .
Image Analyst
2013 年 12 月 24 日
Try this:
% Read in first shape and display it.
I=imread('img.png'); % I'm assuming it's binary. Make it binary if not.
imshow(I)
[rows, columns, numberOfColorChannels] = size(I);
hold on
% Now add second shape, assuming we have just a list of x,y coordinates.
% First make it a binary image.
secondBinaryImage = poly2mask(x, y, rows, columns);
% Get the convex hull of it
secondBinaryImage = bwconvhull(secondBinaryImage);
% Then OR it in with the first binary image.
outputBinaryImage = I | secondBinaryImage; % OR operation.
imshow(outputBinaryImage); % Display result.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!