e0404 / matRad

An open source multi-modality radiation treatment planning sytem developed by e0404 @ DKFZ
http://www.matRad.org
Other
226 stars 176 forks source link

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

Closed Kilong closed 4 months ago

Kilong commented 5 months ago

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

wahln commented 5 months ago

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
Kilong commented 4 months ago

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.

wahln commented 4 months ago

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