brainglobe / brainglobe-template-builder

Build unbiased anatomical templates from individual images
https://brainglobe.github.io/brainglobe-template-builder
BSD 3-Clause "New" or "Revised" License
8 stars 0 forks source link

[BUG] napari widget align transform need some kind of centering? #24

Closed alessandrofelder closed 2 months ago

alessandrofelder commented 2 months ago

Describe the bug Using the napari widget to align najva4 sample gives this screenshot after (what I think is a sensible choice of mid-plane points) image

The alignment seems to work well in the sense that the AP axis is as expected. But the centre is off?

To Reproduce Walk through the napari pre-processing widget with the najva4 sample.

Expected behaviour Sensible choice of mid-plane results in sensible-ish hemisphere.

Computer used (please complete the following information): Ubuntu 22 on Dell Desktop

niksirbi commented 2 months ago

I tried it out myself today on najva4 and I agree there is a bug somewhere in the aligment process. The bug manifests itself in two ways:

  1. the initially estimated midplane points are out of the brain mask, they should be inside
  2. the "straightening" of the midplane seems to work, but there appears to be a missing translation to center the whole thing (see "before" and "after" screenshots below.

I suspect the bug was always there, but didn't manifest itself in the black cap data, because there the field-of-view was barely as large as the brain. The huge field-of-view we have here probably unmasked the problem.

BEFORE alignment_before

AFTER alignment_after

niksirbi commented 2 months ago

Alright, the first manifestation of the bug (estimated points being out of the mask), is no big mystery. My code just ensures that these points will be aligned with the mask's centroid along the symmetry axis (left-right axis). There is no guarantee that the 9 points will fall within the mask itself. That's because the code is written implicitly assuming that the brain will fill most of the field of view, which it clearly doesn't.

See the offending functions here.

I think we should change to actually using the mask's bounding box during point estimation, instead of the whole image.

niksirbi commented 2 months ago

Actually, the 9 points are within the mask in 2/3 axes. It's only along the y axis (axis=1) that they are out of bounds. I'll look into it.