-
Notifications
You must be signed in to change notification settings - Fork 232
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add high-level brain MRI transforms for preprocessing #428
Comments
I would also recommend adding a Additionally, perhaps another option for brain extractor would be useful? |
Hi fernando sorry if I miss other questions, I did not check torchio email for a while ... (and as I get all the email, I do not see the one directly adress to me ...) I agree those are very common step for neuroimaging studies, but not sure if they are so much used for deep learning strategy. but you point out that it is not meant for training ... so what is the use case you have in mind ? |
BUT there are case where there may be no other choice The main advantage to include it in torchio, is to automatically handel the write to file if needed (for nifty reg) but would be nice to have a solution with memory map (may be possible with SimpleElaxtix ?) I recently came to an issue where I need to do a coregistration (motion corrupted volume, have a global displacement regard to original volume, and I am still unsucess to predict it, (despite the Shaw proposition) |
These would be utilities for preprocessing before training, for convenience. Each transform could have different backends, to use the user's preferred method. Here is some code I adapted from MRIPreprocessor: |
I have some use-case too where I need to register 2 images But what the goal next, to make a proper torchio transform (your example is just a main function ... ) ? seems a good idea to me, but I am affraid it will ask a lot of dev ... ? |
I think a generic registration tool is too much. Why would you use TorchIO for that? I was just thinking of very specific usage cases: 1) registering a brain MRI to the MNI space and 2) segmenting the brain from a brain MRI. |
for the same reason as, you, ... and about registration I need to register the motion corrupt image with the original one, so I add it now within my torchio transform but it looks like dirty code ... but just registration it is quickly difficult to apply the correct affine if you play with different tools, (because of different convention), so we should start with one ... |
Well, I wouldn't use TorchIO as a generic registration tool.
Sure, that could maybe be controlled with different backends contributed by users and custom
Aren't you adding the artifacts yourself? Why do you need registration? |
I agree TorchIO is not meant to be a generic registration tool, but since you have a use case, you will need some genericity. I think we agree on that. (one just need to define how generic it will be) When working with multichannel images (T1 T2 ect ...) one may wish that all channel are realign before going to a deep network. This make sense that the voxel values need to be realign in order to gain information of multicontrast inputs Motion corruption is a an other case may be more specific: I can not find a theoretical solution to perfectly demean the motion time course, and I do observer coregistration misalignment between the original and the artifacted volume. I already discuss there #85 . I test the solution published by Shaw but it is an approximation ... |
I was also used to niftyreg, fsl, but it is anoying to have to write the file on the disque ... it worth the try. very good, fast, no file on the disk, and a sitk base ! |
may be I should use a new issue, but I'll do a PR if I can go further So I start witht a basic Rigid coregistration with elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetFixedImage(sitk.ReadImage("fixedImage.nii"))
elastixImageFilter.SetMovingImage(sitk.ReadImage("movingImage.nii"))
elastixImageFilter.SetParameterMap(sitk.GetDefaultParameterMap("rigid"))
elastixImageFilter.Execute() it works fine but I can not find how to derived the affine sitk.PrintParameterMap(elastixImageFilter.GetTransformParameterMap() )
ParameterMap 0:
(CenterOfRotationPoint 0.650002 17.500000 18.650000)
(CompressResultImage "false")
(ComputeZYX "false")
(DefaultPixelValue 0.000000)
(Direction 1.000000 0.000000 0.000000 0.000000 -1.000000 0.000000 0.000000 0.000000 1.000000)
(FinalBSplineInterpolationOrder 3.000000)
(FixedImageDimension 3.000000)
(FixedInternalImagePixelType "float")
(HowToCombineTransforms "Compose")
(Index 0.000000 0.000000 0.000000)
(InitialTransformParametersFileName "NoInitialTransform")
(MovingImageDimension 3.000000)
(MovingInternalImagePixelType "float")
(NumberOfParameters 6.000000)
(Origin -89.849998 126.000000 -71.849998)
(ResampleInterpolator "FinalBSplineInterpolator")
(Resampler "DefaultResampler")
(ResultImageFormat "nii")
(ResultImagePixelType "float")
(Size 182.000000 218.000000 182.000000)
(Spacing 1.000000 1.000000 1.000000)
(Transform "EulerTransform")
(TransformParameters 0.000018 -0.000087 0.000036 9.998980 10.012400 -10.002100)
(UseDirectionCosines "true") any idea how to derive the affine matrix from this (with correct convention) |
I've never used SimpleElastix, I'm not sure. I shared an example with ANTSpy here, it works fine: #428 (comment) |
thanks for the ants example, it is exactly what I need, and it does the job .. since I will need it at training time, it is worth to try a little bit, |
1.9 s? Wow! You're going to perform registrations during training? Very brave :) |
well, I still have the same problem of global displacement after motion simulation (I should submitt an article soon, just on that, the results, is that the solution proposed by Shaw is not working, so I have to go with registration) So I want to test if adding a registrations helps. |
Looking forward to those papers! TorchIO has received a couple of citations from ARAMIS, but not from the CENIR :) |
and @GReguig or I will also do a PR for a new motion transform, (with coregistration, among other adds) |
but to come back to SimpleElastix, I think the only thing I need, is a euler to affine function. for the affine case, (for non linear... later bspline to ...) that is indeed what you do in Resample ... and this is in the itk world (can you make it a more explicit function ?). I have one here from spm, so the nifti world ... i try to make both match /// (grrr) \\ |
I think it is something like this : def euler_to_affine(Euler_angle, Translation, v_center):
#euler angle in radian
rigid_euler = sitk.Euler3DTransform(v_center,Euler_angle[0],Euler_angle[1],Euler_angle[2],Translation)
A1 = np.asarray(rigid_euler.GetMatrix()).reshape(3,3)
c1 = np.asarray(rigid_euler.GetCenter())
t1 = np.asarray(rigid_euler.GetTranslation())
affine = np.eye(4)
affine[:3,:3] = A1
affine[:3,3] = t1+c1 - np.matmul(A1,c1)
# aff = tio.io._from_itk_convention(affine)
return affine Note that I do not do the last conversion tio.io._from_itk_convention(affine) this is because tio.Affine, is applying an affine in the SITK convention (LPS), but I am not sure of it, and I open an explicit question there #693 (comment) |
I personally highly recommend SimpleElastix: reading from image
reading from elastix output file
so process I use looks more like this overall to apply:
|
I think these are out of scope for this library. |
馃殌 Feature
Add some high-level brain MRI transforms for preprocessing.
Motivation
Arguably, there are three preprocessing steps performed on most multimodal neuroimaging studies:
I typically use NiftyReg for registration and ROBEX for brain extraction. As discussed with @ReubenDo, other modern, robust and more Python-friendly tools that could be used for this are SimpleElastix or ANTsPy for registration and HD-BET for brain extraction, similar to what's done in MRIPreprocessor.
A related transform that might be useful is a defacing transform. The simplest way to do this is using a mask defined in the MNI space, therefore this is very related to the MNI registration.
Pitch
Add new preprocessing transforms, not meant to be used during training. Some ideas:
BrainExtraction
,ToMNI
,Coregister
. The requirements would be optional, rising an error with an informative message asking the user to install them usingpip
.@romainVala, do you think this would be useful?
The text was updated successfully, but these errors were encountered: