How do I know the length from the center of the object to the vertical axis edge and the horizontal axis edge?
2 次查看(过去 30 天)
显示 更早的评论
Here's a picture of the pill, you can see that it's not a circle. I want to know the length from the center to the vertical axis edge and the horizontal axis edge
0 个评论
回答(1 个)
Bora Eryilmaz
2023-1-31
You can do something along these lines, where the location of the centroids seems like what you want:
I = imread('image.jpeg');
Ibw = im2bw(I);
Ilabel = bwlabel(Ibw);
stat = regionprops(Ilabel,'centroid');
imshow(I);
hold on;
for i = 1:numel(stat)
plot(stat(i).Centroid(1), stat(i).Centroid(2), 'ro');
stat(i)
end
1 个评论
Image Analyst
2023-1-31
Or
xyCentroids = vertcat(stats); % N by 2 array. x in column 1, y in column 2
% Or if you want them in separate vectors:
xCentroids = xyCentroids(:, 1);
yCentroids = xyCentroids(:, 2);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!