MATLAB Answers

converting boundary to mask

43 views (last 30 days)
lets assume that this is the code i used to identify the boundary. I want display the selected boundary in new window else convert this to mask. is it possible.. some one please help me
I = imread('F:\project_matlab\dataset\002.jpg');
BW = im2bw(I, graythresh(I));
[B,L] = bwboundaries(BW,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end

  0 Comments

Sign in to comment.

Accepted Answer

Dishant Arora
Dishant Arora on 7 Mar 2014
b=bwboundaries(BW); % BW being your binary image
mask=false(size(BW));
for i = 1:length(b)
for j = 1:length(b{i})
ind = b{i}(j,:);
mask(ind(1),ind(2))=1;
end
end
figure
imshow(mask)

  5 Comments

Show 2 older comments
Ibrahim Thorig
Ibrahim Thorig on 12 Mar 2014
dear; actually i want extract image from this image.
Dishant Arora
Dishant Arora on 13 Mar 2014
BW = imfill(BW , 'holes') % will give you desired mask
Image Analyst
Image Analyst on 13 Mar 2014
No need to get boundaries on that image. Simply threshold. The it depends on what you mean by "extract". What does that mean to you? To you mean crop? Do you want the white bar along the bottom of the image also to be included? What about the white torn edge? It can go from simple to complex depending on exactly what you want to do and what kind of images the algorithm can be expected to encounter.

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!