masure width of binary image object

11 views (last 30 days)
soepblik
soepblik on 29 Oct 2021
Commented: Image Analyst on 29 Oct 2021
Hi,
i got an binary image:
The problem is, when i use the regionprops function, the width and height of the yellow object are not correct,see red box.
How can i find the real width and hight of the object?
Edit:
What i want to do is to eliminate regions which are very small. As you can see the yellow regions is small but with the boundingbox function it is just giving the widht and height as seen in the red box. So this region won't be eliminated. So how can i get the real width of the yellow region which is not based on the outside of the region.
  3 Comments
soepblik
soepblik on 29 Oct 2021
hi DGM,
Thanks for your reply. yes i did the boundingbox and plotted it with a rectangle.
See my edit on the original message for more information.
Image Analyst
Image Analyst on 29 Oct 2021
@soepblik, see my answer below. See how my tortuosity demo computes the mean width of the snake-like blob, similar to the shape you have. It should work with your image.

Sign in to comment.

Answers (2)

DGM
DGM on 29 Oct 2021
Edited: DGM on 29 Oct 2021
Normally, if you're trying to remove small objects from a binary image, you do it by area.
Toward that end, bwareaopen() can be used to remove objects below a specified area.
Alternatively, bwareafilt() can be used do things such as removing all but the largest object.
A = imread('blobs.png');
imshow(A)
B = bwareaopen(A,100); % get rid of blobs with <100px area
clc; imshow(B)
C = bwareafilt(A,1); % get rid of everything but the largest blob
clc; imshow(C)
If for some other reason you need to find the width of a line, you can invert the image and use bwdist() to find the distance to the background. The maximum value in the blob region will be its maximum width.
  2 Comments
soepblik
soepblik on 29 Oct 2021
thanks for your reply! the thing is, the region can be big in pixels but still very thin. so i am going to see what i can do with bwdist()
DGM
DGM on 29 Oct 2021
This is one way to find mean "thickness" of objects. It's not exact, but perhaps close enough.
A = imread('blobs.png');
D = bwdist(~A); % get distance map
S = bwmorph(A,'skel',inf); % skeletonize image
[L N] = bwlabel(A);
meanwidths = zeros(N,1);
% remove endpoints until only two are left per blob
for blob = 1:N
thisskel = S & (L == blob);
S(thisskel) = false;
while true
e = bwmorph(thisskel,'endpoints');
if nnz(e)>2
thisskel = thisskel & ~e;
else
break;
end
end
S = S | thisskel; % replace with pruned skeleton
thisMWL = thisskel.*D; % extract locus of maximal width
meanwidths(blob) = mean(thisMWL(thisMWL~=0)); % find mean width
end
% this is the approximate midline of the region
% the distance to the bg is sampled along these lines and averaged
imshow(S)
meanwidths % average thickness for each object
meanwidths = 28×1
1.0000 4.9016 1.0000 1.0000 1.0000 1.1381 2.9082 1.0000 1.0000 1.0000
Alternatively, if you want to get rid of things that aren't very "solid", you might look at the 'extent' or 'solidity' properties (regionprops()) instead of just area. You could even use bwpropfilt() to get rid of blobs accordingly.
A = imread('blobs.png');
% get rid of long, skinny things
B = bwpropfilt(A,'eccentricity',[0 0.99]);
% get rid of things with low solidity
B = bwpropfilt(B,'solidity',[0.5 1]);
imshow(B)

Sign in to comment.


Image Analyst
Image Analyst on 29 Oct 2021
See my attached demo on tortuosity. It computes mean with of a blob. Adapt as needed.

Community Treasure Hunt

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

Start Hunting!