MATLAB Answers

0

i need help with bwboundaries function

Asked by Bekhtaoui Abdelhakim on 29 Mar 2019
Latest activity Answered by Image Analyst
on 16 Aug 2019
hi everyone please i need your help i did not know how to use bwboundaries and boundingbox and bwconncomp on my picture
here is the discription and the image:
"The obtained image will have a dark, thick boundary which has to be eliminated so that thinning won’t be a problem. This is done by using ‘bwboundaries’ to find the
boundary and then using ‘boundingbox’ to define the boundary. Then the maximum no of connected components (bwconncomp) is calculated and eliminated."
INimg1.jpg
please help me

  0 Comments

Sign in to comment.

Products


Release

R2017b

2 Answers


Hi,
Follow this example for drawing boundaries in the image
img1 = imread('your image');
img2=im2bw(img1,graythresh(img1));
img2=~img2;
img2 = bwareaopen(img2,30);// try changing the sensitivity if not proper output
B = bwboundaries(img2,'noholes');//no holes is required in case of your image.

  0 Comments

Sign in to comment.


Answer by Image Analyst
on 16 Aug 2019

I presume your foreground is white and background black. So just call imclearborder(). bwboundaries() and regionprops(BW, 'BoundingBox') are not needed. Then to get the number of connected components:
mask = imclearborder(mask); % Get rid of huge white surround (background).
[labeledImage, numberOfRegions] = bwlabel(mask); % Label what's left.
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% coloredLabels is an RGB image. We could have applied a colormap instead (but only with R2014b and later)
imshow(coloredLabels);
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
caption = sprintf('Pseudo colored labels, from label2rgb().\n%d Blobs are numbered from top to bottom, then from left to right.', numberOfRegions);
title(caption, 'FontSize', 15);

  0 Comments

Sign in to comment.