% check if the weight has the same size as psi
if (~all(size(weight) == size(psi)))
error('Argument error: Size of the weight must be the same as size of the wrapped phase');
end
%论文(公式 15)中的矢量 b 为 dx 和 dy
% vector b in the paper (eq 15) is dx and dy
dx = [wrapToPi(diff(psi, 1, 2)), zeros([size(psi,1),1])]; % 计算x差分
dy = [wrapToPi(diff(psi, 1, 1)); zeros([1,size(psi,2)])]; % 计算y差分
% 将向量 b 乘以权重平方 (W^T * W)
% multiply the vector b by weight square (W^T * W) 将向量 b 乘以权重平方 (W^T * W)
WW = weight .* weight;
WWdx = WW .* dx;
WWdy = WW .* dy;
%对 WWdx 和 WWdy 应用 A^T 就像在非加权情况下获得 rho 一样
% applying A^T to WWdx and WWdy is like obtaining rho in the unweighted case
WWdx2 = [zeros([size(psi,1),1]), WWdx];
WWdy2 = [zeros([1,size(psi,2)]); WWdy];
rk =