Advertisement
ridwan100

uv2mp

Dec 31st, 2023
2,485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.91 KB | None | 0 0
  1. function invmap = uv2mp(uv)
  2.     % uv2mp - Convert uv map to inverse map
  3.     % Author: Ke Ma
  4.  
  5.     % s is the size of the output map
  6.     s = 448;
  7.     % rescale the 1.0 in uv to s which is the size of the output map
  8.     uv = uv * s;
  9.     sx = uv(:, :, 1);
  10.     sy = uv(:, :, 2);
  11.     % valid point
  12.     msk = uv(:, :, 3) > 0.1;
  13.     % sx sy are the value in the forward mapping but the coord in the backward mapping
  14.     sx = sx(msk);
  15.     sy = sy(msk);
  16.     % tx ty are the coord in the forward mapping but the value in the backward mapping
  17.     [ty, tx] = find(msk);
  18.    
  19.     % Use griddata for scattered data interpolation
  20.     Fx = griddata(double(sx), double(sy), double(tx), double(meshgrid(1:s, 1:s)), double(meshgrid(1:s, 1:s))');
  21.     Fy = griddata(double(sx), double(sy), double(ty), double(meshgrid(1:s, 1:s)), double(meshgrid(1:s, 1:s))');
  22.    
  23.     % Concatenate together
  24.     invmap = cat(3, Fx, Fy);
  25. end
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement