[K, V] = convhull(granule);
granule2 = zeros(size(granule));
tmp = granule(K,:)==0; %// all points on the convex hull but not in the granule
tmp2 = tmp(:,1)==tmp(:,2); %// both indices of your granule are zero
granule2(tmp(tmp2)) = 2;
K是与凸包上的点对应的点的行数,V是该凸包所跨越的体积.因此,您可以使用此行索引在granule中查找零索引.
使用以下示例:
granule = rand(1e3,2);
[K, V] = convhull(granule);
granule2 = zeros(size(granule));
tmp = granule(K,:)<0.1; %// all points on the convex hull but not in the granule
tmp2 = tmp(:,1)==tmp(:,2); %// both indices of your granule are below 0.1
granule2(tmp(tmp2)) = 2;
得到总和(tmp2)= 11,因此在这种情况下有11个点在凸包上,并且两个指数都低于0.1(我不能使用== 0,因为我的数组中没有零).
您可能希望根据实际需要为tmp2切换条件.
不出所料,更多的人为此奋斗并实际为此编写代码,请参阅John D’Errico编写的MathWorks Central代码.