- https://www.mathworks.com/help/images/ref/bwboundaries.html (openExample('images/DisplayObjectBoundariesInRedAndHoleBoundariesInGreenExample'))
- https://www.mathworks.com/help/images/ref/imclose.html
How to find the width of this object at its center?
2 次查看(过去 30 天)
显示 更早的评论
As you can see my object is a bit irregular in shape with bigger width at top and bottom, i would like to find out the width of the object at its center (or better smallest width in the central location).
I have used regionprops and bounding box, but it only output the max width.
Thanks in advanced..
0 个评论
回答(1 个)
Prabhan Purwar
2020-7-13
编辑:Prabhan Purwar
2020-7-13
Hi,
Following code may help
Change the threshold value and Morphological parameters according to your need.
clc
close all
clear
img = imread('image.jpeg');
grayImage = rgb2gray(img);
figure
imshow(grayImage);
[pixelCount, grayLevels] = imhist(grayImage);
figure
bar(pixelCount);
% threshold (binarize) the image.
binaryImage = grayImage > 20;
% Get rid of small blobs:
binaryImage = bwareaopen(binaryImage, 500);
% Morphologically close image
binaryImage = imclose(binaryImage, ones(15));
figure
imshow(binaryImage);
hold on
[boundaries, L, N, A] = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
% Find out which are interior boundaries
enclosed_boundaries = find(A(:,1));
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
if ismember(enclosed_boundaries, k)
% It's not an enclosed boundary - it's an outer one. Plot in red.
plot(thisBoundary(:,2), thisBoundary(:,1), 'r', 'LineWidth', 3);
else
% It's an enclosed boundary. Plot in green.
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 3);
end
end
hold off
Kindly have a look at the following links for further references:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!