I have plotted a image using imshow(Image). Now I placed "hold on" command. I have drawn the boundaries of each object in the image as given in code below. How can I capture the new image with boundaries drawn in the plot into an array of pixels ??

4 views (last 30 days)
[B,L,N] = bwboundaries(Image);
imshow(Image); hold on;
for k=1:length(B),
boundary = B{k};
if(k > N)
plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
else
plot(boundary(:,2),boundary(:,1),'r','LineWidth',2);
end
end

Accepted Answer

Image Analyst
Image Analyst on 27 May 2014
Just assign them to an image in a loop inside the loop:
for k=1:length(B)
boundary = B{k};
for k = 1 : size(boundary, 1)
x = boundary(:,2); % Column
y = boundary(:,1); % Row
boundaryImage(y, x) = 255;
end
end
  1 Comment
Bhuvanesh
Bhuvanesh on 27 May 2014
Actually your idea helped me a lot . There is a slight change which is to be applied if only boundary is to be colored:-
Instead of
x = boundary(:,2); % Column
y = boundary(:,1); % Row
It should be :-
x = boundary(k,2); % Column
y = boundary(k,1); % Row
Thanks a lot :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!