- 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?
1 回表示 (過去 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..![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/329105/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/329105/image.jpeg)
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!