# How can I plot the diameters of an irregularly shaped region in an image?

3 vues (au cours des 30 derniers jours)
Asher Zaidi le 28 Juin 2018
Commenté : Asher Zaidi le 29 Juin 2018
This is my code:
props = regionprops(BW, 'Area', 'Perimeter','Centroid','EquivDiameter');
allAreas = [props.Area];
allPerimeters = [props.Perimeter];
centroids = cat(1, props.Centroid);
allDiameters = [props.EquivDiameter];
figure(1);
imshow(BW);
title('Outlines, from bwboundaries()', 'FontSize', 1);
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
hold on;
boundaries = bwboundaries(BW);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'r', 'LineWidth', 2);
end
hold on;
plot(centroids(:,1),centroids(:,2), 'b*')
hold off
This gives me the following image:
I got the actual values of the diameters through "EquivDiameter", but how can I plot the diameters of each individual blob on top of their centroids?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Image Analyst le 28 Juin 2018
Try this:
xCentroids = centroids(1:2:end);
yCentroids = centroids(2:2:end);
for k = 1 : length(xCentroids )
txt = sprintf(' %.2f', allDiameters(k));
text(xCentroids(k), yCentroids(k), txt, 'FontSize', 20, 'FontWeight', 'bold');
end
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Image Analyst le 29 Juin 2018
OK. You might make the font size a bit smaller. Honestly I don't know why you want the diameters on the image if there are so many of them.
Asher Zaidi le 29 Juin 2018
Sure, thanks!

Connectez-vous pour commenter.

### Plus de réponses (1)

Matt J le 28 Juin 2018
Modifié(e) : Matt J le 28 Juin 2018
You can use the text() command to write the diameters onto the image at desired locations.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Image Category Classification dans Help Center et File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by