I have not tested performance, but here is an algorithm for obtaining weighted centroids and areas. This should work with Jacket as well as with matlab (depending on the type of input).
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
PS I'm a developer at AccelerEyes. Sorry for delay.
EDIT : cleared the code a bit.
source share