CoBrALab / RABIES

fMRI preprocessing pipeline and analysis tools adapted for rodent images. Visit the full documentation at https://rabies.readthedocs.io/en/stable/
Other
35 stars 14 forks source link

Atlas file inputted into RABIES differs in orientation and fov to the output files of RABIES. #338

Open KarisColyerPatel opened 10 months ago

KarisColyerPatel commented 10 months ago

Hey All,

Using the output from the DR step as input for fsl randomise was effective! I am now trying to load the atlas (Fischer344) I inputted into RABIES, but there appears to be issues with the orientation and FOV (they differ between the files). Is there an output from the preprocessing step (of the atlas labels) that I could use to input into fsleyes. I checked the commonspace_labels but there are still issues with the FOV! Also the files contained here are per rat rather than averaged across my sample.

Gab-D-G commented 10 months ago

Hey Karis, the orientation is standardized to RAS during preprocessing, so this may differ from your inputs. Preprocessing will output a re-oriented/resampled version of the template and atlas files provided (there is commonspace_labels as you mentionned, but also commonspace_resampled_template for the resampled template). The resolution will be matching your functional images (or what was provided to --commonspace_resampling), as well as the FOV. Can you be more precise regarding the mismatch in FOV you observe with the commonspace_labels files? Is it relative to the commonspace preprocessed functional images?

gdevenyi commented 10 months ago

My guess here is that the input files are in non-standard orientation.

Can you open a representative set of input files (and the atlas) in itk-snap and share screenshots?

KarisColyerPatel commented 10 months ago

Of course! Yes, exactly the mismatch is relative to the commonspace preprocessed functional images. Please see below! File outputted from DR (files are the commonspace preprocessed functional images) filename sub-01_r1_a1_d1_b1_bold_combined_cleaned_DR_maps.nii.gz

sizeof_hdr 348 data_type FLOAT64 dim0 4 dim1 56 dim2 28 dim3 41 dim4 30 dim5 1 dim6 1 dim7 1 vox_units mm time_units Unknown datatype 64 nbyper 8 bitpix 64 pixdim0 1.000000 pixdim1 0.300000 pixdim2 1.000000 pixdim3 0.300000 pixdim4 0.801000 pixdim5 0.000000 pixdim6 0.000000 pixdim7 0.000000 vox_offset 352 cal_max 0.000000 cal_min 0.000000 scl_slope 1.000000 scl_inter 0.000000 phase_dim 0 freq_dim 0 slice_dim 0 slice_name Unknown slice_code 0 slice_start 0 slice_end 0 slice_duration 0.000000 toffset 0.000000 intent Unknown intent_code 0 intent_name intent_p1 0.000000 intent_p2 0.000000 intent_p3 0.000000 qform_name Scanner Anat qform_code 1 qto_xyz:1 0.300000 0.000000 0.000000 -9.140401 qto_xyz:2 0.000000 1.000000 0.000000 -16.190514 qto_xyz:3 0.000000 0.000000 0.300000 -0.845504 qto_xyz:4 0.000000 0.000000 0.000000 1.000000 qform_xorient Left-to-Right qform_yorient Posterior-to-Anterior qform_zorient Inferior-to-Superior sform_name Scanner Anat sform_code 0 sto_xyz:1 0.000000 0.000000 0.000000 0.000000 sto_xyz:2 0.000000 0.000000 0.000000 0.000000 sto_xyz:3 0.000000 0.000000 0.000000 0.000000 sto_xyz:4 0.000000 0.000000 0.000000 1.000000 sform_xorient Unknown sform_yorient Unknown sform_zorient Unknown file_type NIFTI-1+ file_code 1 descrip

filename resampled_template.nii.gz

sizeof_hdr 348 data_type FLOAT32 dim0 3 dim1 68 dim2 114 dim3 50 dim4 1 dim5 0 dim6 0 dim7 0 vox_units mm time_units Unknown datatype 16 nbyper 4 bitpix 32 pixdim0 1.000000 pixdim1 0.250000 pixdim2 0.250000 pixdim3 0.250000 pixdim4 0.000000 pixdim5 0.000000 pixdim6 0.000000 pixdim7 0.000000 vox_offset 352 cal_max 0.000000 cal_min 0.000000 scl_slope 1.000000 scl_inter 0.000000 phase_dim 0 freq_dim 0 slice_dim 0 slice_name Unknown slice_code 0 slice_start 0 slice_end 0 slice_duration 0.000000 toffset 0.000000 intent Unknown intent_code 0 intent_name intent_p1 0.000000 intent_p2 0.000000 intent_p3 0.000000 qform_name Scanner Anat qform_code 1 qto_xyz:1 0.250000 0.000000 0.000000 -9.140400 qto_xyz:2 0.000000 0.250000 0.000000 -16.190500 qto_xyz:3 0.000000 0.000000 0.250000 -0.845504 qto_xyz:4 0.000000 0.000000 0.000000 1.000000 qform_xorient Left-to-Right qform_yorient Posterior-to-Anterior qform_zorient Inferior-to-Superior sform_name Scanner Anat sform_code 0 sto_xyz:1 0.000000 0.000000 0.000000 0.000000 sto_xyz:2 0.000000 0.000000 0.000000 0.000000 sto_xyz:3 0.000000 0.000000 0.000000 0.000000 sto_xyz:4 0.000000 0.000000 0.000000 1.000000 sform_xorient Unknown sform_yorient Unknown sform_zorient Unknown file_type NIFTI-1+ file_code 1 descrip
aux_file

filename sub-01_r1_a1_d1_b1_bold_EPI_anat_labels.nii.gz

sizeof_hdr 348 data_type INT16 dim0 3 dim1 56 dim2 28 dim3 41 dim4 1 dim5 1 dim6 1 dim7 1 vox_units mm time_units Unknown datatype 4 nbyper 2 bitpix 16 pixdim0 1.000000 pixdim1 0.300000 pixdim2 1.000000 pixdim3 0.300000 pixdim4 0.000000 pixdim5 0.000000 pixdim6 0.000000 pixdim7 0.000000 vox_offset 352 cal_max 0.000000 cal_min 0.000000 scl_slope 1.000000 scl_inter 0.000000 phase_dim 0 freq_dim 0 slice_dim 0 slice_name Unknown slice_code 0 slice_start 0 slice_end 0 slice_duration 0.000000 toffset 0.000000 intent Unknown intent_code 0 intent_name intent_p1 0.000000 intent_p2 0.000000 intent_p3 0.000000 qform_name Scanner Anat qform_code 1 qto_xyz:1 0.300000 0.000000 0.000000 -9.140401 qto_xyz:2 0.000000 1.000000 0.000000 -16.190514 qto_xyz:3 0.000000 0.000000 0.300000 -0.845504 qto_xyz:4 0.000000 0.000000 0.000000 1.000000 qform_xorient Left-to-Right qform_yorient Posterior-to-Anterior qform_zorient Inferior-to-Superior sform_name Scanner Anat sform_code 1 sto_xyz:1 0.300000 0.000000 -0.000000 -9.140401 sto_xyz:2 0.000000 1.000000 -0.000000 -16.190514 sto_xyz:3 0.000000 0.000000 0.300000 -0.845504 sto_xyz:4 0.000000 0.000000 0.000000 1.000000 sform_xorient Left-to-Right sform_yorient Posterior-to-Anterior sform_zorient Inferior-to-Superior file_type NIFTI-1+ file_code 1 descrip
aux_file

gdevenyi commented 10 months ago

The headers don't actually tell us what we need to know, which is the orientation of the data itself relative to the header coordinates interpreted by a tool we understand. Can you please produce some screenshots from ITK-snap. Thanks.

KarisColyerPatel commented 10 months ago

Ah yes I think you are right.

Screenshot 2023-11-14 at 22 45 24

Although see below

Screenshot 2023-11-14 at 22 49 31

The commonspace preprocessed functional data does appear to be registered to the resampled template and labels. But the warning "Displaying images with different orientations/fields of view!" is still shown in fsleyes. Would you guys suggest that I start from the top and sort out the differing orientations between the functional data and atlas?

gdevenyi commented 10 months ago

I'm sorry, I must ask again.

Please provide screenshots of representative input data, as well as the atlas you're using with ITK-snap.

KarisColyerPatel commented 10 months ago
Screenshot 2023-11-15 at 10 25 07 Screenshot 2023-11-15 at 10 26 53

As you can see when loading the two files, only one is visible at at time! This is the same if I try to overlay the files or have them side by side.

KarisColyerPatel commented 10 months ago
Screenshot 2023-11-15 at 10 31 01
Gab-D-G commented 10 months ago

Hey, I'm not sure I fully understand. Did you check if the resampled_template file does overlap with the functional files? Can you show those side by side, and then show the resampled_template next to the Fischer template? The differences between the original Fischer template file and the resampled_template should be two-fold: a conversion to RAS orientation (this function https://github.com/CoBrALab/RABIES/blob/a62094cf0737b8241d70f73fb12aed215634891b/rabies/preprocess_pkg/utils.py#L194), and the resampling of the template resolution ot match that of you anatomical scans (the function here https://github.com/CoBrALab/RABIES/blob/a62094cf0737b8241d70f73fb12aed215634891b/rabies/utils.py#L42). One of those two operations may cause the differences.

gdevenyi commented 10 months ago

The orientation of the input files is as expected. They are properly aligned with the anatomical directions.

@Gab-D-G perhaps you should be completely explicit on which output files are which, and what space they are expected to be in, after that @KarisColyerPatel can use ITK-snap to confirm said alignment.

Gab-D-G commented 10 months ago

Sorry if that wasn't clear. I would expect the resampled_template.nii.gz to be properly aligned with the preprocessed timeseries found in the commonspace_bold folder. We should confirm this is true. I don't see the overlap displayed in the previous comments. Then we can compare resampled_template.nii.gz to the original Fischer template to see where the mismatch originates from. Can you do this for us @KarisColyerPatel ?

I would suspect something to do with RAS orientation, but I may be wrong. In the resample_image_spacing function, this resampling operation is carried out https://github.com/CoBrALab/RABIES/blob/a62094cf0737b8241d70f73fb12aed215634891b/rabies/utils.py#L56C70-L56C70, which should in my understanding only change voxel size and change the matrix dimensions accordingly, but can you take a look @gdevenyi to confirm this is accurate?