spinalcordtoolbox / PAM50

https://github.com/neuropoly/spinalcordtoolbox
2 stars 1 forks source link

Histology atlas has inconsistent dimensions #8

Closed jcohenadad closed 1 year ago

jcohenadad commented 1 year ago

Version: 19a56824c5b479d520f46c9285ef2bb738da8034 (after #6)

Some files under the histology/ atlas do not have the same size and pixdims, yet they should. Example:

julien-macbook:~/code/PAM50/histology $ sct_image -i PAM50_200um_Naxons.nii.gz -header | grep dim
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0]
julien-macbook:~/code/PAM50/histology $ sct_image -i PAM50_200um_MVF.nii.gz -header | grep dim
dim     [3, 110, 85, 515, 1, 1, 1, 1]
pixdim      [-1.0, 0.195455, 0.194118, 0.199029, 0.0, 0.0, 0.0, 0.0]

The two outliers are PAM50_200um_EquivDiameter.nii.gz and PAM50_200um_Naxons.nii.gz.

BTW: The Z dimension should probably match that from the PAM50 (ie: 0.5), because there is no 'more' information contained in these single-slice histology data (ie: one per level). That way we might be able to save physical space (useful for https://github.com/spinalcordtoolbox/PAM50/issues/7).

valosekj commented 1 year ago

Thank you for pointing this out!

Just note that the inconsistent dimensions were already presented before the https://github.com/spinalcordtoolbox/PAM50/commit/19a56824c5b479d520f46c9285ef2bb738da8034 (and https://github.com/spinalcordtoolbox/PAM50/pull/6):

# checkout to the version before https://github.com/spinalcordtoolbox/PAM50/pull/6
$ git checkout r20220527

$ cd histology
$ for file in *nii.gz;do echo ${file};sct_image -i ${file} -header | grep dim | head -2;echo "";done
PAM50_200um_AVF.nii.gz
dim     [3, 110, 85, 515, 1, 1, 1, 1]
pixdim      [-1.0, 0.195455, 0.194118, 0.199029, 0.0, 0.0, 0.0, 0.0]

PAM50_200um_Eccentricity.nii.gz
dim     [3, 110, 85, 515, 1, 1, 1, 1]
pixdim      [-1.0, 0.195455, 0.194118, 0.199029, 0.0, 0.0, 0.0, 0.0]

PAM50_200um_EquivDiameter.nii.gz
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0]

PAM50_200um_EquivDiameter14.nii.gz
dim     [3, 110, 85, 515, 1, 1, 1, 1]
pixdim      [-1.0, 0.195455, 0.194118, 0.199029, 0.0, 0.0, 0.0, 0.0]

PAM50_200um_EquivDiameter48.nii.gz
dim     [3, 110, 85, 515, 1, 1, 1, 1]
pixdim      [-1.0, 0.195455, 0.194118, 0.199029, 0.0, 0.0, 0.0, 0.0]

PAM50_200um_MVF.nii.gz
dim     [3, 110, 85, 515, 1, 1, 1, 1]
pixdim      [-1.0, 0.195455, 0.194118, 0.199029, 0.0, 0.0, 0.0, 0.0]

PAM50_200um_Naxons.nii.gz
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0]
jcohenadad commented 1 year ago

~Maybe we should go for 110x85x205 @0.08x0.08x0.5mm? (ie: best of both worlds).~

mistake-- let's go with 0.08x0.08x0.5

valosekj commented 1 year ago

Using sct_resample -i ${file} -mm 0.083333x0.083333x0.5 -x linear I can bring all files to:

dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0]

Running across all files that do not have 0.083333x0.083333x0.5 pixdim:

$ cd histology
$ for file in *nii.gz;do;pixdim=$(sct_image -i ${file} -header | grep pixdim | awk '{print $3}');if [[ ! ${pixdim} =~ 0.083333 ]];then sct_resample -i ${file} -mm 0.083333x0.083333x0.5 -x linear;fi;done

Now, check that resampled files (with _r suffix) corresponds with PAM50_200um_EquivDiameter.nii.gz and PAM50_200um_Naxons.nii.gz:

$ for file in PAM50_200um_AVF_r.nii.gz PAM50_200um_Eccentricity_r.nii.gz PAM50_200um_EquivDiameter.nii.gz PAM50_200um_EquivDiameter14_r.nii.gz PAM50_200um_EquivDiameter48_r.nii.gz PAM50_200um_MVF_r.nii.gz PAM50_200um_Naxons.nii.gz;do echo ${file};sct_image -i ${file} -header | grep dim | head -2;echo "";done
PAM50_200um_AVF_r.nii.gz
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 1.0, 1.0, 1.0, 1.0]

PAM50_200um_Eccentricity_r.nii.gz
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 1.0, 1.0, 1.0, 1.0]

PAM50_200um_EquivDiameter.nii.gz
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0]

PAM50_200um_EquivDiameter14_r.nii.gz
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 1.0, 1.0, 1.0, 1.0]

PAM50_200um_EquivDiameter48_r.nii.gz
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 1.0, 1.0, 1.0, 1.0]

PAM50_200um_MVF_r.nii.gz
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 1.0, 1.0, 1.0, 1.0]

PAM50_200um_Naxons.nii.gz
dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0]

Or alternatively, I can downsample PAM50_200um_EquivDiameter.nii.gz and PAM50_200um_Naxons.nii.gz using sct_resample -i PAM50_200um_EquivDiameter.nii.gz -mm 0.195455x0.194118x0.199029 from

dim     [3, 258, 198, 205, 1, 1, 1, 1]
pixdim      [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0]

to

dim     [3, 110, 85, 515, 1, 1, 1, 1]
pixdim      [-1.0, 0.195455, 0.194118, 0.199029, 1.0, 1.0, 1.0, 1.0]
jcohenadad commented 1 year ago

what's the pixdim = 1 for the last dimensions?

joshuacwnewton commented 1 year ago

May be related to;

tl;dr this is expected behavior coming directly from the nibabel library that happens when saving images

jcohenadad commented 1 year ago

Indeed, but it is weird to have them inconsistent across files (some have 0, some have 1)

jcohenadad commented 1 year ago

also, we should rename "PAM50_200um_MVF_r.nii.gz" to "PAM50_80um_MVF.nii.gz"

valosekj commented 1 year ago

also, we should rename "PAM50_200um_MVF_r.nii.gz" to "PAM50_80um_MVF.nii.gz"

Sure, the output shown in https://github.com/spinalcordtoolbox/PAM50/issues/8#issuecomment-1481341714 with the _r suffix was just for discussion.

valosekj commented 1 year ago

Indeed, but it is weird to have them inconsistent across files (some have 0, some have 1)

I found out it is possible to set the last four numbers of pixdim to zero using img.header["pixdim"][4:] = 0. Therefore, as a short-term solution for this particular case, I added this zeroing to resampling.py.

Here are prints from the updated resampling.py showing how pixdim is changing:

image
After applying this step, resampled images have the same `dim` and `pixdim` as non-resampled images: ```console $ for file in PAM50_200um_AVF_r.nii.gz PAM50_200um_Eccentricity_r.nii.gz PAM50_200um_EquivDiameter.nii.gz PAM50_200um_EquivDiameter14_r.nii.gz PAM50_200um_EquivDiameter48_r.nii.gz PAM50_200um_MVF_r.nii.gz PAM50_200um_Naxons.nii.gz;do echo ${file};sct_image -i ${file} -header | grep dim | head -2;echo "";done PAM50_200um_AVF_r.nii.gz dim [3, 258, 198, 205, 1, 1, 1, 1] pixdim [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0] PAM50_200um_Eccentricity_r.nii.gz dim [3, 258, 198, 205, 1, 1, 1, 1] pixdim [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0] PAM50_200um_EquivDiameter.nii.gz dim [3, 258, 198, 205, 1, 1, 1, 1] pixdim [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0] PAM50_200um_EquivDiameter14_r.nii.gz dim [3, 258, 198, 205, 1, 1, 1, 1] pixdim [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0] PAM50_200um_EquivDiameter48_r.nii.gz dim [3, 258, 198, 205, 1, 1, 1, 1] pixdim [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0] PAM50_200um_MVF_r.nii.gz dim [3, 258, 198, 205, 1, 1, 1, 1] pixdim [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0] PAM50_200um_Naxons.nii.gz dim [3, 258, 198, 205, 1, 1, 1, 1] pixdim [-1.0, 0.083333, 0.083333, 0.5, 0.0, 0.0, 0.0, 0.0] ```
jcohenadad commented 1 year ago

What's the size of all these files? (related to #7)

valosekj commented 1 year ago

What's the size of all these files? (related to https://github.com/spinalcordtoolbox/PAM50/issues/7)

To keep the conversation clean i moved the answer to https://github.com/spinalcordtoolbox/PAM50/issues/7#issuecomment-1483041672

(sorry i should not have asked it in this issue thread in the first place)