brainglobe / brainreg

Automated 3D brain registration with support for multiple species and atlases.
https://brainglobe.info/documentation/brainreg/index.html
BSD 3-Clause "New" or "Revised" License
119 stars 27 forks source link

[BUG] "Check orientation" button in napari not consistent with registration results for hemisphere #200

Closed pderdeyn closed 2 months ago

pderdeyn commented 3 months ago

Describe the bug Orientation doesn't seem to be consistent between the "Check orientation" button in napari brainreg plugin versus when running the registration. The "left-right" lateral direction seems to be flipped between the two for my useage. Note that I am using a single hemisphere

To Reproduce I have one hemisphere of an imaged brain to align with an atlas. Using the check orientation button in napari's brain reg plugin, I find that my data orientation should be lpi for a brain geometry of Left hemisphere (screenshot 1). However, when I run this hemisphere through brain reg, I find that the atlas is actually the incorrect lateral orientation and left and right need to be flipped (screenshot 2). I'm able to fix my brain my switching to rpi (screenshot 4), even though the "check orientation" results don't look correct anymore (screenshot 3).

Expected behaviour Registration should occur with the correct orientation if the "Check orientation" results look good

Screenshots

"Check orientation" results for lpi image

Registration results for lpi image

"Check orientation" results for rpi image

Registration results for rpi image

Computer used (please complete the following information):

adamltyson commented 3 months ago

Thanks for raising this @pderdeyn, we'll take a look.

@alessandrofelder I wonder if this is related to what we saw with napari in 2D/3D on Friday? Is it possible that there's something going on with 2D and 3D visualisation in napari, so that in one of the views, the data is (or at least appears to be) flipped?

alessandrofelder commented 3 months ago

I wonder if this is related to what we saw with napari in 2D/3D on Friday?

Maybe... we should find a clear way to check this for ourselves (that doesn't require neuroanatomy knowledge) and then discuss it with the napari community if needed?

adamltyson commented 3 months ago

A quick test on the latest napari suggests that it isn't a napari thing, this looks fine to me: 2D 2d

3D 3d

adamltyson commented 3 months ago

I had a quick look at this last week, and it looks like the issue is somewhere in the intersection of setting the hemisphere and creating the projections.

adamltyson commented 2 months ago

I had a quick look at this last week, and it looks like the issue is somewhere in the intersection of setting the hemisphere and creating the projections.

Actually I think I'm wrong, I think the issue is just in creating the projections. I (very scientifically!) created an image with an L marked into it in two axes, so that you can always tell which axis is which. 3d

This brain is psl and registering it with this orientation appears to work correctly. The downsampled_standard.tiff image is correctly oriented: downsampled_standard

This suggests that brainreg and brainglobe-space are working properly. Of course they could be cancelling each other out, but I'm assuming that these two mature packages are correct.

However, if I click on Check orientation then the brain appears flipped (hard to see, but there's a slight mark in the left hemisphere, which is now rendered on the right).

orientation

I assume this is the reason for the issue reported here. I haven't worked out why this is happening yet.

adamltyson commented 2 months ago

I think I'm missing something here. In the orientation checking function, the input data (napari layer) is reoriented (using brainglobe-space) to the atlas orientation. This looks correct (L is in the correct place):

remapped_image

However, when looking at the projection images in the above comment, it seems that the first projection (bottom left) is correct (assuming the view is front to back), but the second (bottom middle) is not (assuming the view is top down). I don't think we can say anything about the third (bottom right).

alessandrofelder commented 2 months ago

@IgorTatarnikov and I spent some time diagnosing this. Our conclusions are:

pderdeyn commented 2 months ago

Fantastic. Thanks for the fix you all <3

adamltyson commented 2 months ago

Hey @pderdeyn, a new version with this fix should be out in an hour or so. pip install brainreg -U will update.

pderdeyn commented 2 weeks ago

I just wanted to confirm that I tried this today on an updated version and it works as expected. Thanks again