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

Segmentation error (with docker image) #14

Open
anisha1807 opened this issue Oct 22, 2020 · 10 comments
Open

Segmentation error (with docker image) #14

anisha1807 opened this issue Oct 22, 2020 · 10 comments

Comments

@anisha1807
Copy link

image
subject1-session1.additional.log

I want to perform cortical segmentation of neonatal brain. I was able to successfully install the docker image and I tested two nifti files (preterm and term subjects) but this error persists.

@schuhschuh
Copy link
Member

Thanks, could you also attach the *.additional.err file?

@anisha1807
Copy link
Author

anisha1807 commented Oct 22, 2020

subject1-session1.additional.err.txt

I created a text file since it doesn't allow me to directly attach the .err file. But the content is the same.

@schuhschuh
Copy link
Member

Very sorry for the late reply, this error usually suggests that there is no overlap between the images to be registered (or maybe that one image is completely empty). It may be worthwhile to check any previous registration output that was computed, e.g., an affine transformation supposed to align the images before deformable registration.

@anisha1807
Copy link
Author

TC_0432_T2_reg.nii.gz
Here is the file I am trying to process.

@schuhschuh
Copy link
Member

Thanks, @anisha1807. I was able to reproduce the issue.

In short, see at the end regarding a bug in scripts/misc/pipeline.sh which causes this issue, where target and source input images to the mirtk register command are in the wrong order. Below a more detailed tracing of the issue.

Looking at the input to the registration command, it appears that one of the transformations which should be the inverse of another is indeed actually almost identical to this other transformation. More concretely, I looked at the following:

docker cp dhcp-container:/usr/src/structural-pipeline/parameters/../atlases/non-rigid-v2/T2/template-40.nii.gz .
docker cp dhcp-container:/usr/src/structural-pipeline/parameters/../atlases/non-rigid-v2/T2/template-44.nii.gz .

mirtk view \
    -target template-{40,44}.nii.gz \
    -source workdir/subject1-session1/restore/T2/subject1-session1_restore_bet.nii.gz \
    -dofin workdir/subject1-session1/dofs/template-44-subject1-session1-n.dof.gz \
           workdir/subject1-session1/dofs/subject1-session1-template-44-n.dof.gz

When looking at these images, I have to check the box "Invert transformation" in both cases to achieve the expected alignment in the Viewer. This suggests that subject1-session1-template-44-n.dof.gz is correct, but template-44-subject1-session1-n.dof.gz is not as it should be the inverse of it.

At least one of these transformation files is computed by the segmentation/pipeline.sh script, which in turn simply executes the Draw-EM command

mirtk neonatal-segmentation /data/workdir/subject1-session1/T2/subject1-session1.nii.gz 44 -t 4 -c 1 -p 1 -v 1 -atlas non-rigid-v2

I thus first suspected the issue is with Draw-EM. Above neontal-segmentation command registers the 44 week template to the bias corrected input image at this line. This computes the transformation dofs/subject1-session1-template-44-n.dof.gz, i.e., the one we identified above as correct (which explains why the Draw-EM segmentations in workdir/subject1-session1/segmentations/ look fine). Looking through all the steps of mirtk neonatal-segmentation script, it does indeed not produce nor use the incorrect inverse transformation. So the issue is more likely in the dHCP pipeline then.

Indeed it seems another registration is executed in the additional pipeline:

if [ ! -f dofs/template-$age-$subj-n.dof.gz ];then
run mirtk register $T2masked $template_T2/template-$age.nii.gz -dofout dofs/template-$age-$subj-n.dof.gz -parin $registration_config_template -threads $threads -v 0
fi

^^^ This command is the culprit.

The order of target and source suggest that the output transformation maps points from input image to template space, but the naming of the output transformation suggests it should be the mapping from template to input space rather.

@jcupitt Can you have a look at this? This bug seems to be present since @amakropoulos initial commit in 2017. Odd though that it wouldn't have caused issue before?!? Has maybe something else changed more recently?

Also, instead of this extra registration step, it would make sense to just use

mirtk invert-dof dofs/subject1-session1-template-44-n.dof.gz dofs/template-44-subject1-session1-n.dof.gz

when the image to template mapping is available from the Draw-EM output.

jcupitt added a commit that referenced this issue Nov 15, 2020
It looks as if a copy-paste error back in 2017 was causing the template
to subject DOF to be reversed.

Also revise formatting in this section to be clearer.

See #14
@schuhschuh
Copy link
Member

schuhschuh commented Nov 15, 2020

@jcupitt found the solution! [EDIT: :-) seems John was faster actually fixing it than me posting this update...]

The incorrect code block referenced above seems obsolete, and was supposed to be replaced by the lines below it:

if [ ! -f dofs/template-$age-$subj-n.dof.gz ];then
run mirtk invert-dof dofs/$subj-template-$age-n.dof.gz dofs/template-$age-$subj-i.dof.gz
run mirtk register $template_T2/template-$age.nii.gz $T2masked -dofin dofs/template-$age-$subj-i.dof.gz -dofout dofs/template-$age-$subj-n.dof.gz -parin $registration_config_template -threads $threads -v 0
run rm dofs/template-$age-$subj-i.dof.gz
fi

Removing below lines from scripts/misc/pipeline.sh resolves the issue.

if [ ! -f dofs/template-$age-$subj-n.dof.gz ];then
run mirtk register $T2masked $template_T2/template-$age.nii.gz -dofout dofs/template-$age-$subj-n.dof.gz -parin $registration_config_template -threads $threads -v 0
fi

Thanks, @anisha1807, for bringing this to our attention and sorry for the long wait. @jcupitt will submit a fix soon, which should then also update the Docker image.

@schuhschuh
Copy link
Member

For reference, @amakropoulos also fixed this issue less than 1 month ago in the original repo DevelopingHCP@5f7942d

@jcupitt
Copy link

jcupitt commented Nov 15, 2020

And Andreas found the issue heh.

schuhschuh referenced this issue in DevelopingHCP/structural-pipeline Nov 15, 2020
@jcupitt
Copy link

jcupitt commented Nov 15, 2020

Oh goodness, I didn't realize the original repo was still being updated. Are there any other fixes we should pick up?

@schuhschuh
Copy link
Member

schuhschuh commented Nov 15, 2020

Not for now [I think]. I'll be talking to Antonis next week. There are some other MIRTK issues still outstanding. He had planned to then contribute those upstream once ready and working, I belief.

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

No branches or pull requests

3 participants