function invmap = uv2mp(uv) % uv2mp - Convert uv map to inverse map % Author: Ke Ma % s is the size of the output map s = 448; % rescale the 1.0 in uv to s which is the size of the output map uv = uv * s; sx = uv(:, :, 1); sy = uv(:, :, 2); % valid point msk = uv(:, :, 3) > 0.1; % sx sy are the value in the forward mapping but the coord in the backward mapping sx = sx(msk); sy = sy(msk); % tx ty are the coord in the forward mapping but the value in the backward mapping [ty, tx] = find(msk); % Use griddata for scattered data interpolation Fx = griddata(double(sx), double(sy), double(tx), double(meshgrid(1:s, 1:s)), double(meshgrid(1:s, 1:s))'); Fy = griddata(double(sx), double(sy), double(ty), double(meshgrid(1:s, 1:s)), double(meshgrid(1:s, 1:s))'); % Concatenate together invmap = cat(3, Fx, Fy); end