Drawing two shapes on one image

조회 수: 3 (최근 30일)
med-sweng
med-sweng 2013년 12월 23일
편집: Youssef Khmou 2013년 12월 24일
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.

답변 (2개)

Youssef  Khmou
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
med-sweng
med-sweng 2013년 12월 23일
@Youssef KHMOU. Thanks for you reply. The issue is in adding another shape. If I add another shape, I want to see it alongside with the first shape. How can this be performed?
Youssef  Khmou
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
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.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by