Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help description for sct_image -setorient is misleading #3741

Closed
joshuacwnewton opened this issue Mar 24, 2022 · 1 comment · Fixed by #3938
Closed

Help description for sct_image -setorient is misleading #3741

joshuacwnewton opened this issue Mar 24, 2022 · 1 comment · Fixed by #3938
Labels
documentation category: readthedocs, sourceforge, or SCT courses priority:MEDIUM SCT API: image.py context: user requested Raised by user on the SCT forum/email/GitHub. Be sure to notify them when fixed in a release.

Comments

@joshuacwnewton
Copy link
Member

joshuacwnewton commented Mar 24, 2022

The help description for -setorient says the following:

ORIENTATION OPERATIONS:
  -getorient            Get orientation of the input image (default: False)
  -setorient {RIP,LIP,RSP,LSP,RIA,LIA,RSA,LSA,IRP,ILP,SRP,SLP,IRA,ILA,SRA,SLA,RPI,LPI,RAI,LAI,RPS,LPS,RAS,LAS,PRI,PLI,ARI,ALI,PRS,PLS,ARS,ALS,IPR,SPR,IAR,SAR,IPL,SPL,IAL,SAL,PIR,PSR,AIR,ASR,PIL,PSL,AIL,ASL}
                        Set orientation of the input image (only modifies the header).
  -setorient-data {RIP,LIP,RSP,LSP,RIA,LIA,RSA,LSA,IRP,ILP,SRP,SLP,IRA,ILA,SRA,SLA,RPI,LPI,RAI,LAI,RPS,LPS,RAS,LAS,PRI,PLI,ARI,ALI,PRS,PLS,ARS,ALS,IPR,SPR,IAR,SAR,IPL,SPL,IAL,SAL,PIR,PSR,AIR,ASR,PIL,PSL,AIL,ASL}
                        Set orientation of the input image's data (does NOT modify the header, but the data). Use with care !

However, -setorient doesn't only modify the header. It modifies the data array, too:

# axes inversion (flip)
data = im_src_data[::inversion[0], ::inversion[1], ::inversion[2]]
# axes manipulations (transpose)
if perm == [1, 0, 2]:
data = np.swapaxes(data, 0, 1)
elif perm == [2, 1, 0]:
data = np.swapaxes(data, 0, 2)
elif perm == [0, 2, 1]:
data = np.swapaxes(data, 1, 2)
elif perm == [2, 0, 1]:
data = np.swapaxes(data, 0, 2) # transform [2, 0, 1] to [1, 0, 2]
data = np.swapaxes(data, 0, 1) # transform [1, 0, 2] to [0, 1, 2]
elif perm == [1, 2, 0]:
data = np.swapaxes(data, 0, 2) # transform [1, 2, 0] to [0, 2, 1]
data = np.swapaxes(data, 1, 2) # transform [0, 2, 1] to [0, 1, 2]
elif perm == [0, 1, 2]:
# do nothing
pass
else:
raise NotImplementedError()

Which makes sense, I think? If you're reorienting an image, you want the header metadata to correspond to the data array; you can't update one without also updating the other.

This came up when responding to a question on the forum: https://forum.spinalcordmri.org/t/rpi-orientation-issue/848

@joshuacwnewton joshuacwnewton added documentation category: readthedocs, sourceforge, or SCT courses SCT API: image.py context: user requested Raised by user on the SCT forum/email/GitHub. Be sure to notify them when fixed in a release. labels Mar 24, 2022
@jcohenadad
Copy link
Member

Which makes sense, I think?

Yes, I agree with you. I wrongly wrote the text "only modifies the header" as I was looking at the help of fslorient which mentions that note at the end:

julien-macbook:~ $ fslorient 
Usage: fslorient <main option> <filename>

  where the main option is one of:
    -getorient             (prints FSL left-right orientation)
    -getsform              (prints the 16 elements of the sform matrix)
    -getqform              (prints the 16 elements of the qform matrix)
    -setsform <m11 m12 ... m44>  (sets the 16 elements of the sform matrix)
    -setqform <m11 m12 ... m44>  (sets the 16 elements of the qform matrix)
    -getsformcode          (prints the sform integer code)
    -getqformcode          (prints the qform integer code)
    -setsformcode <code>   (sets sform integer code)
    -setqformcode <code>   (sets qform integer code)
    -copysform2qform       (sets the qform equal to the sform - code and matrix)
    -copyqform2sform       (sets the sform equal to the qform - code and matrix)
    -deleteorient          (removes orient info from header)
    -forceradiological     (makes FSL radiological header)
    -forceneurological     (makes FSL neurological header - not Analyze)
    -swaporient            (swaps FSL radiological and FSL neurological)

       Note: the stored data order is never changed here - only the header info.
       To change the data storage use fslswapdim.

But it's clear that sct_image -setorient is more the equivalent of fslswapdim.

Thank you for catching that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation category: readthedocs, sourceforge, or SCT courses priority:MEDIUM SCT API: image.py context: user requested Raised by user on the SCT forum/email/GitHub. Be sure to notify them when fixed in a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants