sct-pipeline / ukbiobank-spinalcord-csa

Measure of the averaged cross-sectional area (cord CSA) between C2 and C3 of the spinal cord with UK Biobank Brain MRI dataset.
MIT License
3 stars 1 forks source link

Subtract unaligned images to compare gradcorr with ukbiobank gradcorr #12

Closed sandrinebedard closed 3 years ago

sandrinebedard commented 3 years ago

Description :

To compare the results of gradient distorsion correction, the image corrected with the gradcorr of the pipeline using coeff.grad from Montreal Heart Institute was subtracted from the processed image of UK biobank. The spinal cord of the processed images of Uk biobank was cut off. To be able to subtract the images, the same transformation has to be done on the image with gradcorr of the pipeline.

Input data:

For T1w:

For T2w:

Problems:

Steps to reproduce:

Using:

The sames steps were applided to T2w

  1. Apply gradcorr with coeff.grad from Montreal Heart Institue and gradunwrap tool.

    gradient_unwarp.py sub_1000032_T1w.nii.gz sub-1000032_T1w_gradcorr.nii.gz siemens -g coeff.grad -n
  2. Crop gradcorr image with sct_crop_image. with ukbiobank processed image as -refparameter.

sct_crop_image -i sub_1000032_T1w_gradcorr.nii.gz -o sub_1000032_T1w_gradcorr_crop.nii.gz -ref T1.nii.gz
  1. Asjust the shapes. The output file has now a shape of (161, 221,181) T1.nii.gz file has a shape of (162, 222, 182) The output file of sct_crop_image doesn't have the same shape as the ref T1.nii.gz. To adjsut this, in flseyes, I cropped the T1.nii.gz to the shape (161, 221,181) --> T1_crop.nii.gz. Maybe the non-alignment of the images after is an artefact of this operation. There is clearly a better solution for this problem.

  2. Subtract images.

    sct_math -i T1_crop.nii.gz  -o sub_1000032_T1w_diff_uk_ICM.nii.gz -sub sub_1000032_T1w_gradcorr_crop.nii.gz

Results:

While looking at T1w_crop.nii.gz and at sub_1000032_T1w_gradcorr_crop.nii.gz in FSLeyes, we can see the non-alignment of the images. Here is the result of the subtraction:

sub_1000032_T1w_diff_uk_ICM Other operations were done on the ukbiobank processed image, the image intensity and contrats are not the same as in the original image.

The exact operation was done with T2w (T1 flair), here is the result: sub_1000032_T2w_diff_uk_ICM png The shape of T2 crop was this time: (154, 222,182) and for T2w processed: (162 ,222, 182). We can observe a more obvious gradient in the difference image. While observing T2_FLAIR.nii.gz and sub_1000032_T2w.nii.gz in FSLeyes, we can see that the brain and spinal cord are not aligned, they shifted.

sandrinebedard commented 3 years ago

@jcohenadad if you could take a look at this, thank you :)

jcohenadad commented 3 years ago

@sandrinebedard I'm trying to reproduce your results, starting from step 1:

gradient_unwarp.py sub_1000032_T1w.nii.gz sub-1000032_T1w_gradcorr.nii.gz siemens -g coeff.grad -n

However, I cannot locate sub_1000032_T1w.nii.gz. On duke, I went to the following folder:

duke:projects/ukbank/demo_ukbank/1000032/T1

But I am seeing these files:

-rwx------  1 julien  staff       313  2 Oct  2019 T1.json
-rwx------  1 julien  staff   9236047  5 Oct  2019 T1.nii.gz
-rwx------  1 julien  staff   2785603  5 Oct  2019 T1_brain.nii.gz
-rwx------  1 julien  staff    383866  5 Oct  2019 T1_brain_mask.nii.gz
-rwx------  1 julien  staff   3844779  5 Oct  2019 T1_brain_to_MNI.nii.gz
drwx------  1 julien  staff       264  2 Sep 16:13 T1_fast
drwx------  1 julien  staff      1078  2 Sep 16:13 T1_first
-rwx------  1 julien  staff  16686194  5 Oct  2019 T1_orig_defaced.nii.gz
-rwx------  1 julien  staff   4680569  5 Oct  2019 T1_unbiased_brain.nii.gz
drwx------  1 julien  staff       264  2 Sep 16:13 transforms

Could you please document in the README where are the files you are using for your analysis, and if needed, how to generate the "BIDSified" versions of the files by adding the appropriate instructions in the README.

EDIT 2020-11-28 21:21:52 After re-reading your instructions, I re-interpreted "The image sub_1000032_T1w.nii.gz was used, it corresponds to : T1_orig_defaced.nii.gz in ukbiobank database.". What you meant is that sub_1000032_T1w.nii.gz is the exact same file as T1_orig_defaced.nii.gz, but it was just renamed. Right? If that's indeed the case, I will go ahead with the debugging, but in the meantime it would be great if you could add documentation about the location of the BIDSified data. Thanks

jcohenadad commented 3 years ago

@sandrinebedard ha! you're right, the T1.nii.gz processed by UKBuibank does include a slight X and Y pixel shift, as can be seen in the animation below, switching between the T1.nii.gz image and the grad-corrected T1_orig_defaced.nii.gz image:

anim

In addition to this shift, I recall that B1 inhomogeneity bias was corrected by an N4 filter (it's a spatially smooth filter that corrected for intensity bias in the image), which makes the comparison even more difficult.

At this point, it's probably pointless to try to make a comparison with the T1 image, although qualitatively speaking, both images look "similar", which is a good sign, suggesting we can "trust" our coeff.grad file.

P.S. You did not need to crop the images. Instead you could have simply registered them into the same coordinate system, followed by the subtraction.

Syntax and results ```bash # Resample the sub-1000032_T1w_gradcorr.nii.gz using the affine transformation matrix from the NIfTI header sct_register_multimodal -i sub-1000032_T1w_gradcorr.nii.gz -d T1.nii.gz -identity 1 # subtract the two images sct_maths -i T1.nii.gz -sub sub-1000032_T1w_gradcorr_reg.nii.gz -o T1_minus_sub-1000032_T1w_gradcorr_reg.nii.gz ``` ![Screen Shot 2020-11-28 at 9 40 38 PM](https://user-images.githubusercontent.com/2482071/100530636-62723380-31c2-11eb-9fb2-bda090f0ff0b.png)
sandrinebedard commented 3 years ago

DIT 2020-11-28 21:21:52 After re-reading your instructions, I re-interpreted "The image sub_1000032_T1w.nii.gz was used, it corresponds to : T1_orig_defaced.nii.gz in ukbiobank database.". What you meant is that sub_1000032_T1w.nii.gz is the exact same file as T1_orig_defaced.nii.gz, but it was just renamed. Right? If that's indeed the case, I will go ahead with the debugging, but in the meantime it would be great if you could add documentation about the location of the BIDSified data. Thanks

@jcohenadad yes, that was what I meant, sorry for the confusion! I am updating the documentation about de BIDS dataset, thank you for pointing that out.

At this point, it's probably pointless to try to make a comparison with the T1 image, although qualitatively speaking, both images look "similar", which is a good sign, suggesting we can "trust" our coeff.grad file.

Ok perfect in that case!

P.S. You did not need to crop the images. Instead you could have simply registered them into the same coordinate system, followed by the subtraction.

Ahhh i see! Thanks for the info, good to know!

jcohenadad commented 3 years ago

Closing because https://github.com/sct-pipeline/ukbiobank-spinalcord-csa/issues/6#issuecomment-777748358