You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
987 B

%--------------------------
% @Author: Jingqiao Hu
% @Date: 2022-01-06 11:30:36
% @LastEditTime: 2022-05-09 21:01:13
% cvt energy
%--------------------------
function [E, dE] = cvt_energy(seeds, cenP)
npnts = size(seeds, 1);
E0 = sum((seeds - cenP) .^ 2, 2); % [n,1]
dE0 = 2 * (seeds - cenP); % [n,2]
E = sum(E0);
dE0(:, 4) = 0;
dE = reshape(dE0', [], 1);
end
function [E, dE] = cvt_energy_rho(seeds, cpnts, rho, cenP)
npnts = size(seeds, 1);
rhoP = zeros(npnts, 1);
% compute centroid & its rho
% figure;
parfor i = 1 : npnts
% find the nearest point of current seed
pi = seeds(i, :);
dist = vecnorm(cpnts - pi, 2, 2);
[~, idx] = min(dist);
rhoP(i) = rho(idx);
end
E0 = sum((seeds - cenP) .^ 2, 2); % [n,1]
dE0 = 2 * (seeds - cenP); % [n,2]
E = sum(E0 .* rhoP);
dE = dE0 .* rhoP;
dE(:, 4) = 0;
dE = reshape(dE', [], 1);
end