Drawing two shapes on one image
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Youssef Khmou
am 23 Dez. 2013
Bearbeitet: Youssef Khmou
am 24 Dez. 2013
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 Kommentare
Youssef Khmou
am 24 Dez. 2013
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
am 24 Dez. 2013
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 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!