masure width of binary image object
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2021-10-29
@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.
回答(2 个)
DGM
2021-10-29
编辑:DGM
2021-10-29
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 个评论
DGM
2021-10-29
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
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)
Image Analyst
2021-10-29
See my attached demo on tortuosity. It computes mean with of a blob. Adapt as needed.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!