e0404/matRad

How to correct *.nii.gz format images and RT structure data back to the correct position

Kilong opened this issue · 3 comments

I am using the branch feature/niftireader. I found that after importing the image, it seems to have been rotated 90 degrees counterclockwise compared to the ‘.mat’ files in the ‘matRad-feature-niftireader\phantoms’ folder. I guess this is due to the inconsistency between the niftiread() function and matlab's weird (j,i,k)-Indexing the image. How should I rotate the imported '.nii.gz’ file to match the one in the example for subsequent planning and design?
image

Often it is enough to apply Matlab's "permute" the images. What you se is not "really" a rotation, but a switching of the first two indices in the image.

Here's some (untested) code, which should at least point you in the right direction:

permutation = [2 1 3];

for s = 1:ct.numOfCtScen
  ct.cubeHU{s} = permute(ct.cubeHU{s},permutation);
  if isfield(ct,'cube') %This does not always exist
    ct.cube{s} = permute(ct.cube{s},permutation); 
  end

  %Now do the same for the index lists storing the VOI indices.
  for v = 1:size(cst,1)
    mask = false(ct.cubeDim);
    mask(cst{v,4}{s}) = true;
    cst{v,4}{s} = find(permute(mask,permutation));
  end
end

Thank you for your help, I have successfully imported and performed the dose calculation, but there might be a small issue with the code you provided above, there is a missing 'end' in the loop.

Thanks, edited it for future users stumbling across this issue.