Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: added Elastix registration (issue #334) #341

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

che85
Copy link
Member

@che85 che85 commented Jan 24, 2018

fixes #334

  • SliceTrackerRegistrationLogic expects registration algorithm as a
    parameter in order to be interchangeable
  • IRegistrationAlgorithm is the interface that needs to be implemented
    in order to add new registration algorithm
  • new configuration entries
  • adapted SliceTrackerRegistration widget and cli
  • gentle handling if preferred algorithm doesn't exist with giving
    notification and using fallback algorithm (default: BRAINS)

TODO: use own parameter files needs to possible

Class diagram

image

* SliceTrackerRegistrationLogic expects registration algorithm as a
  parameter in order to be interchangeable
* IRegistrationAlgorithm is the interface that needs to be implemented
  in order to add new registration algorithm
* new configuration entries
* adapted SliceTrackerRegistration widget and cli
* gentle handling if preferred algorithm doesn't exist with giving
  notification and using fallback algorithm (default: BRAINS)

TODO: use own parameter files needs to possible
@fedorov
Copy link
Member

fedorov commented Jan 24, 2018

I would change IRegistrationAlgorithm to ImageRegistrationTool

@fedorov
Copy link
Member

fedorov commented Jan 24, 2018

Should there be an algorithm-specific implementation of the resampling method?

@fedorov
Copy link
Member

fedorov commented Jan 24, 2018

I think it makes sense for the abstract class to have functions that define the output required from the algorithm. As is, it is unclear what are the expectations from run().

@che85
Copy link
Member Author

che85 commented Jan 24, 2018

I would change IRegistrationAlgorithm to ImageRegistrationTool

Yeah I can do that

Should there be an algorithm-specific implementation of the resampling method?

I don't know which resampling method you mean

I think it makes sense for the abstract class to have functions that define the output required from the algorithm. As is, it is unclear what are the expectations from run().

Technically you can always expect an output volume and an output transform. Both are stored in the RegistrationResult instance. Maybe I should decouple it from RegistrationResult?

@che85
Copy link
Member Author

che85 commented Jan 24, 2018

Should there be an algorithm-specific implementation of the resampling method?

Do you mean the part, where I am applying the initial rigid registration transform to the moving label/volume?

@fedorov
Copy link
Member

fedorov commented Jan 24, 2018

I thought that elastix does not produce a Slicer node for the deformable transform, and we need to use transformix to apply it to the dataset, that's what I meant.

@che85
Copy link
Member Author

che85 commented Jan 24, 2018

I thought that elastix does not produce a Slicer node for the deformable transform, and we need to use transformix to apply it to the dataset, that's what I meant.

In SlicerElastix you can select an output transform which is an vtkMRMLTransformNode.

It works in SliceTracker this way, but there are some issues with elastix registration so we need to look into the parameter files.

@che85
Copy link
Member Author

che85 commented Jan 24, 2018

@fedorov That's probably what you were looking for: https://github.com/lassoan/SlicerElastix/blob/master/Elastix/Elastix.py#L577-L586

@che85
Copy link
Member Author

che85 commented Jan 25, 2018

@fedorov, @Kmacneil0102 feel free to play with the parameter files. For now I only activated the BSpline_Parameters.txt to be used, but also tried a combination of rigid, affine and bSpline. All three parameter files were added with commit 768f6dd

CLI execution

Slicer --no-main-window --no-splash --python-script SliceTrackerRegistration.py -fv {fixedVolume} -mv {movingVolume} -fl {fixedLabel} -ml {movingLabel} -o {outputDir} -t "Elastix"

The combination though gives me errors:

...

itk::ExceptionObject (0x109096cf8)
Location: "ElastixTemplate - Run()"
File: /Users/kitware/Dashboards/Nightly/S-0-E-b/SlicerElastix-build/elastix/src/Common/CostFunctions/itkAdvancedImageToImageMetric.hxx
Line: 1065
Description: itk::ERROR: AdvancedMattesMutualInformationMetric(0x108863c00): Too many samples map outside moving image buffer: 78 / 402

Error occurred during actual registration.

Errors occurred!

Maybe helpful resources:
[1] http://lists.bigr.nl/pipermail/elastix/2016-April/002252.html
[2] http://elastix.isi.uu.nl/FAQ.php#Q_TooManySamples

@fedorov
Copy link
Member

fedorov commented Jan 25, 2018

@che85, as we discussed and tested at the project week, elastix initializer is not good enough to deal with this kind of data. You should use BRAINS CenterOfROI initializer, and then pass the resulting transform to elastix.

@che85
Copy link
Member Author

che85 commented Jan 25, 2018

@fedorov That's what I did, when you look at [1].

  1. run [2]
  2. apply resulting transform to moving volume and label
  3. run elastix with fixed volume/label and transformed moving volume/label
  4. apply BRAINS transform to elastix transform so that we have the whole package (rigid + deformable)
  5. invert BRAINS transform and apply to moving volume and label so that we get back the originals

Am I missing something or doing anything wrong?

If so, I will look into that next week when I get back.

[1] https://github.com/che85/SliceTracker/blob/integrate_Elastix/SliceTracker/SliceTrackerUtils/algorithms/registration.py#L236-L247
[2] https://github.com/che85/SliceTracker/blob/integrate_Elastix/SliceTracker/SliceTrackerUtils/algorithms/registration.py#L164-L172

@fedorov
Copy link
Member

fedorov commented Jan 25, 2018

I didn't try. Is it the same dataset we used at the PW?

@fedorov
Copy link
Member

fedorov commented Jan 25, 2018

In your code, you run rigid registration after the ROI initialization. At the PW we just ran the initializer, and passed the result to elastix.

@che85
Copy link
Member Author

che85 commented Jan 29, 2018

You are right. I somehow memorized that I clicked the rigid checkbox in the BRAINS registration. Will correct that now.

@che85
Copy link
Member Author

che85 commented Feb 5, 2018

Some more information regarding how we addressed the integration of Elastix:

Elastix doesn’t support using the center of ROI( in Elastix it’s called mask) align. That’s why we choose the following approach to be used.

Pipeline

BRAINSFit ROI initialization → transform moving label and volume → using generic (all) preset that includes rigid and BSpline parameter files → running registration

In the first place, rigid registration failed sometimes, so we decided to change the parameter file for the rigid registration.

Parameters_Rigid.txt

  • AutomaticTransformInitialization had to be set to false
  • NumberOfResolutions seemed to be working better with 2 instead of 4

After changing the parameters, I was not able to reproduce the errors, that we had earlier.

Bad_result.zip

@fedorov
Copy link
Member

fedorov commented Jun 28, 2018

Didn't realize this - but this PR being open means Elastix has not been integrated, right?

@che85
Copy link
Member Author

che85 commented Feb 9, 2019

@fedorov It would be interesting which version we are using right now in production. This PR never got merged

@fedorov
Copy link
Member

fedorov commented Feb 10, 2019

Indeed, too bad it didn't get merged while you were still here. Now I don't want to do it not to mess up something! I should check which version we are using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider using Elastix registration as an alternative registration solution
2 participants