How to find the width of this object at its center?

1 visualizzazione (ultimi 30 giorni)
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..

Risposte (1)

Prabhan Purwar
Prabhan Purwar il 13 Lug 2020
Modificato: Prabhan Purwar il 13 Lug 2020
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:

Community Treasure Hunt

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

Start Hunting!

Translated by