- 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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Prabhan Purwar
el 13 de Jul. de 2020
Editada: Prabhan Purwar
el 13 de Jul. de 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:
0 comentarios
Ver también
Categorías
Más información sobre Computer Vision with Simulink en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!