使用Matlab的图像处理工具箱,我可以使用regionprops function找到加权质心。这是因为该函数可以通过PixelList返回图像的每个标记部分的WeightedCentroid或像素索引列表,然后很容易计算加权质心。然而,jacket's support in regionprops仅返回一个未加权的质心(或早先使用bwlabel获得的二进制“岛”的质心)。这意味着关于像素位置的信息以某种方式被用来找到这些质心。
我如何访问jacket的regionprops信息,关于它用来计算未加权质心的像素列表,以便我可以使用它来计算加权质心?(这样做的一个重要原因是因为函数find不能在gfor循环中使用,否则可以find bwlabel的不同输出值...)
发布于 2012-11-20 01:03:49
我还没有测试性能,但这里有一个算法来获得加权质心和面积。这应该适用于Jacket和matlab (取决于输入类型)。
function [WC, WA] = WeightedMoments(L, I);
[m, n] = size(L);
[keys, idx] = sort(L(:));
% Get weights and locations in sorted order
w = I(idx);
idx = idx - 1; % Convert to 0-index for simplicity
x = floor(idx / m);
y = idx - x * m;
% Location of the starting point of each region.
locs = find([diff(keys); 1]);
% Weighted area and locations
Msum = cumsum([w, x.*w, y.*w]);
Mloc = diff(Msum(locs,:));
M00 = Mloc(:, 1);
M10 = Mloc(:, 2);
M01 = Mloc(:, 3);
% Weighted centroids and areas
WC = [M10 ./ M00, M01 ./ M00] + 1; % Convert back to 1-index
WA = M00;
end另外,我是AccelerEyes的一名开发人员。很抱歉让你久等了。
编辑:稍微清理了一下代码。
https://stackoverflow.com/questions/13314551
复制相似问题