Reputation: 48926
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.
EDIT
This is what I did:
I=imread('img.png');
....
....
selectedRegions1=119;
bb = vertcat( rg( selectedRegions1 ).BoundingBox );
bb(:,3:4) = bb(:,1:2) + bb(:,3:4) - 1;
totBB = [min( bb(:,1:2), [], 1 ), max( bb(:,3:4), [], 1 ) ]
nVal=50;
totBB =
239.5000 202.5000 252.5000 211.5000
xx1 =239.5000 + rand(nVal,1).*(252.5000- 239.5000);
yy1 = 202.5000 + rand(nVal,1).*(211.5000- 202.5000);
k1 = convhull(xx1,yy1);
I=imread('img.png');
imshow(I)
hold on
plot(xx1(k1),yy1(k1),'r-',xx1,yy1,'b+');
fill(xx1(k1),yy1(k1),[1 1 1])
selectedRegions2=[181,186,193,198];
bb = vertcat( rg( selectedRegions2 ).BoundingBox );
bb(:,3:4) = bb(:,1:2) + bb(:,3:4) - 1;
totBB = [min( bb(:,1:2), [], 1 ), max( bb(:,3:4), [], 1 ) ]
totBB =
355.5000 100.5000 399.5000 146.5000
xx2 =355.5000 + rand(nVal,1).*(399.5000- 355.5000);
yy2 = 100.5000 + rand(nVal,1).*( 146.5000- 100.5000);
k2 = convhull(xx2,yy2);
plot(xx2(k2),yy2(k2),'r-',xx2,yy2,'b+');
fill(xx2(k2),yy2(k2),[1 1 1])
BW = roipoly( I, xx1(k1), yy1(k1) );
BW = roipoly( I, xx2(k2), yy2(k2) );
imshow(BW)
Thanks.
Upvotes: 0
Views: 946
Reputation: 12689
The polygon region has already been described by your x(k)
and y(k)
, so there is no more interactive part for you to draw another polygon. imshow(BW)
is the same as your previous 3 lines code.
You can save/imwrite
the BW
and imread
it again , then use roipoly
to draw your own polygons.
If you draw the polygons all automatically, you can just use:
BW = roipoly( I, xx1(k1), yy1(k1) );
BW1 = roipoly( I, xx2(k2), yy2(k2) );
imshow(BW|BW1)
Upvotes: 1