gridResampleExample.m 853 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. % Sets up an example for a 3D grid resampling operation
  2. % Old grid dimensions
  3. M = 512;
  4. N = 512;
  5. Q = 10;
  6. dx = 0.1;
  7. dy = 0.1;
  8. dz = 0.2
  9. % resolution after resampling (if empty, resolution is unchanged
  10. dxNew = 2*dx;
  11. dyNew = 2*dy;
  12. dzNew = 0.5*dz;
  13. % create the phantom
  14. Pslice = phantom(M);
  15. P = zeros(M,N,Q,'single');
  16. for k=1:Q
  17. P(:,:,k) = Pslice;
  18. end
  19. % original data coordinates
  20. x = [-(M-1)/2:(M-1)/2]*dx;
  21. y = [-(N-1)/2:(N-1)/2]*dy;
  22. z = [-(Q-1)/2:(Q-1)/2]*dz;
  23. % new coordinate system
  24. xNew = [x(1):dxNew:x(end)];
  25. yNew = [y(1):dyNew:y(end)];
  26. zNew = [z(1):dzNew:z(end)];
  27. % do the resampling
  28. Pp = gridResample3D(x,y,z,P,xNew,yNew,zNew,'linear');
  29. % plot results
  30. figure; imagesc(P(:,:,ceil(Q/2))); colormap gray;
  31. title('Original image','FontSize',14);
  32. figure; imagesc(Pp(:,:,ceil(numel(zNew)/2))); colormap gray;
  33. title('Resampled image','FontSize',14);