kschan0214 / sepia

Matlab GUI pipeline application for quantitative susceptibility mapping (QSM)
MIT License
46 stars 10 forks source link

AHEAD template corregistration #86

Open Shashank-Vijayaprasadh opened 3 months ago

Shashank-Vijayaprasadh commented 3 months ago

Dear Kwok, After running SEPIA for the participants, now I want to corregister the subject Chimap to AHEAD template. So, I used the SEPIA GUI for this but the problem is, it is very slow. I have used the latest version of SEPIA 1.2.2.5. It has been 10 hours of running it in MATLAB, but it is still not finished. Is there something that should be changed in the option to make it run faster? Would be great to know how to solve this!

PS: I have attached some images of the config I used along with some command line steps that came as it was getting executed sepia ahead config_1pp AHEAD_template fitting AHEAD_template fitting_1 AHEAD_template fitting2

kschan0214 commented 3 months ago

Dear Shashank,

Just want to clarify: is that the processing time of running the segmentation on the DCCN cluster using 1 core only? The segmentation is based on non-linear registration which is generally computationally intensive. The use of the AHEAD atlas could be even slower due to the high spatial resolution (0.5x0.5x0.5 mm iso) of the atlas. I have some ideas on how to speed up the process but haven't had time to implement them yet.

If you are running the analysis on the DCCM cluster, there are a few tricks to speed up the process depending on the size of your cohort and how familiar you are with image registration. Here are some of my suggestions:

  1. Run the analysis with multiple cores ANTs supports multithread processing so you can speed up the process by running the script on a multi-core session. You can check https://hpc.dccn.nl/docs/cluster_howto/compute_torque.html#specifying-resource-requirement to see how to request multiple cores in one session.

  2. Run multiple subjects in parallel One thing I usually do is to create a shell script to automatically create Matlab processing scripts for multiple subjects and submit the jobs to the cluster simultaneously so that you don't need to wait for one subject at a time. You might still need to be mindful about the computational resource available though (e.g. CPU and Matlab license availability)

  3. Create group templates and use them for segmentation instead Another strategy I used is to first register all subjects into the same space (e.g. MNI 1mm), and create a T1w, Chimp, GRE magnitude group template by averaging all subjects together. Once the templates are created, you can use them for AHEAD atlas segmentation like what you do on a single subject. The advantage is that you only have one very expensive registration remains (AHEAD-group template registration), which you can speed up using Suggestion#1. The drawback is that there might be some steps you need to perform outside of SEPIA.

How many datasets do you have in your study in total?

Best,

Kwok

Shashank-Vijayaprasadh commented 3 months ago

Dear Kwok, Thank you for your suggestions! I am completely new to image registrations but I am very interested in learning them. I have made a script which can submit multiple jobs to the cluster for the participants. I have 108 participants for who I want to use the registration. But the only thing is that I want to bring it back to the subject space where I want to fit a VTA template which I have in the AHEAD atlas space (which I want to do a bit later) so that it is more personalized. sepia_ahead_jobcommand

This is the command I used to submit it to cluster which I have adapted from the SEPIA command used to submit to cluster. I was also keen on seeing if a group template could be developed, but the VTA template is already in the AHEAD space so, I was thinking maybe I would lose some voxels by doing so. But after reading your suggestion, if its possible to warp the VTA template from the AHEAD space to group template space without losing much precision and if it will speed up the process, I would be happy to give it a try.

Please let me know what you think!

Much thanks, Shashank

Shashank-Vijayaprasadh commented 2 months ago

Dear Kwok, I have tried using 4 cores for processing without changing any configuration for co-registration to AHEAD template. It is still taking very long and is not finishing running even for one participant so I dont want to run it for all participants without knowing how long it might take to finish.

[cid:e541524f-d53a-4eb4-b013-d8674b7eb1be] This is where it is becoming very slow. Jose suggested maybe change some settings in the t1w_2_t1w_atlas_template, but i'm not sure if changing the iterations would make the computation less intensive or if it would affect the co-registration a lot. I am unsure on what might be going wrong and would be great to have your input on it!

Many thanks, Shashank Vijayaprasadh


From: Kwok-Shing Chan @.> Sent: Wednesday, April 3, 2024 5:43 PM To: kschan0214/sepia @.> Cc: Vijayaprasadh, S. (Shashank) @.>; Author @.> Subject: Re: [kschan0214/sepia] AHEAD template corregistration (Issue #86)

You don't often get email from @.*** Learn why this is importanthttps://aka.ms/LearnAboutSenderIdentification

Dear Shashank,

Just want to clarify: is that the processing time of running the segmentation on the DCCN cluster using 1 core only? The segmentation is based on non-linear registration which is generally computationally intensive. The use of the AHEAD atlas could be even slower due to the high spatial resolution (0.5x0.5x0.5 mm iso) of the atlas. I have some ideas on how to speed up the process but haven't had time to implement them yet.

If you are running the analysis on the DCCM cluster, there are a few tricks to speed up the process depending on the size of your cohort and how familiar you are with image registration. Here are some of my suggestions:

  1. Run the analysis with multiple cores ANTs supports multithread processing so you can speed up the process by running the script on a multi-core session. You can check https://hpc.dccn.nl/docs/cluster_howto/compute_torque.html#specifying-resource-requirement to see how to request multiple cores in one session.

  2. Run multiple subjects in parallel One thing I usually do is to create a shell script to automatically create Matlab processing scripts for multiple subjects and submit the jobs to the cluster simultaneously so that you don't need to wait for one subject at a time. You might still need to be mindful about the computational resource available though (e.g. CPU and Matlab license availability)

  3. Create group templates and use them for segmentation instead Another strategy I used is to first register all subjects into the same space (e.g. MNI 1mm), and create a T1w, Chimp, GRE magnitude group template by averaging all subjects together. Once the templates are created, you can use them for AHEAD atlas segmentation like what you do on a single subject. The advantage is that you only have one very expensive registration remains (AHEAD-group template registration), which you can speed up using Suggestion#1. The drawback is that there might be some steps you need to perform outside of SEPIA.

How many datasets do you have in your study in total?

Best,

Kwok

— Reply to this email directly, view it on GitHubhttps://github.com/kschan0214/sepia/issues/86#issuecomment-2034965964, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BGPZFFA77DFOSQZOYD25A23Y3QPTTAVCNFSM6AAAAABFJOQ3U6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZUHE3DKOJWGQ. You are receiving this because you authored the thread.

kschan0214 commented 1 month ago

Hi Shashank

Sorry for the late reply. I cannot see the image but I guess the process slow down during SyN, is that the case?

Reducing the number of iterations may or may not speed up the process, depending on how many iterations needed for the cost function to converge. In my experience, each step often takes 50-100 iterations to converge (convergence <1e-6). Current maximum allowed iterations are 500 (4x subsampled), 500 (2x subsampled), and 250 (full resolution). Unless these numbers are reduced to, say <50, it won’t speed up the registration process.

Another way is to set a larger convergence value (say 1e-5), i.e.,

--convergence [500x500x250,1e-5,10] \

This might reduce the number of iterations by at least ~20-30 on each step. It might still be ok for your application because the optimisation cost comes mostly from the cortex (difficult to match on volumetric data), and you are only interested in subcortical nuclei of the AHEAD atlas. You can overlay the atlas labels on the registered image to check the registration quality.

Alternatively, you can also try using a mask focusing on the registration on the subcortical nuclei (which is my idea to speed up the registration). You can generate a dilated mask based on the AHEAD labels to include all nuclei and some white matter tissue (let’s called this mask_AHEAD.nii.gz). Then you can incorporate this mask to the script as

antsRegistration \
        --dimensionality 3 --float 0 \
        --output [${t1_2_atlas_vol},${t1_2_atlas_template_nii}] \
        --interpolation Linear \
        --winsorize-image-intensities [0.005,0.995] \
        --use-histogram-matching 0 \
        --initial-moving-transform [${ref_vol},${in_vol},1] \
        --transform Rigid[0.1] \
        --metric MI[${ref_vol},${in_vol},1,32,Regular,0.1] \
        --convergence [1000x500x250x100,1e-6,10] \
        --shrink-factors 4x3x2x1 \
        --smoothing-sigmas 3x2x1x0vox \
        --transform Affine[0.1] \
        --metric MI[${ref_vol},${in_vol},1,32,Regular,0.1] \
        --convergence [500x250,1e-6,10] \
        --shrink-factors 2x1 \
        --smoothing-sigmas 1x0vox \
        --transform SyN[0.1,3,0] \
        --metric CC[${ref_vol},${in_vol},1,2] \
        --convergence [500x500x250,1e-6,10] \
        --shrink-factors 4x2x1 \
        --smoothing-sigmas 2x1x0vox \
        --x mask_AHEAD.nii.gz \
        --verbose 1 

I think this should speed up the process quite a lot but I haven't had the chance to test this yet.