matlab中的regionprop函数可以计算'ConvexArea'和'ConvexHull',如何根据这些数据计算周长凸度?
代码:
clc;
clear;
a = imread('circlesBrightDark.png');
bw = a < 100;
imshow(bw)
title('Image with Circles')
stats = regionprops('table',bw,'Centroid','ConvexHull')
k=2
outlineConvex = stats.ConvexHull{k};
P = perimeter(outlineConvex);
答案 0 :(得分:1)
凸度通常定义为凸包的周长与物体周长的比率。使用regionprops
找到凸包的周长有点困难,因为这个特征没有内置。这应该有效:
stats = regionprops(bw,'Perimeter','ConvexImage');
for ii=1:length(stats)
cp = regionprops(+stats(ii).ConvexImage,'Perimeter');
stats(ii).Convexity = cp(1).Perimeter / stats(ii).Perimeter;
end
(我现在手头没有MATLAB来测试这个,Octave没有实现'ConvexImage'功能。)
使用DIPimage toolbox,您可以执行以下操作:
msr = measure(bw,[],{'Perimeter','ConvexPerimeter'});
Convexity = msr.ConvexPerimeter ./ msr.Perimeter;
答案 1 :(得分:0)
首先,获取二进制图像的凸包,然后计算该图像的周长。
% Binarize image
bwImg = imbinarize(image);
% Generate convex hull image from binary image
convexHull = bwconxhull(bwImg);
% Calculate the perimeter of the convex hull
ConvexHullPerimeter = regionprops(convexHull, 'Perimeter');