brainglobe / brainglobe-atlasapi

A lightweight python module to interact with atlases for systems neuroscience
https://brainglobe.info/documentation/brainglobe-atlasapi/index.html
BSD 3-Clause "New" or "Revised" License
124 stars 32 forks source link

[BUG] `allen_cord_20um` meshes are not centered #330

Closed adamltyson closed 3 weeks ago

adamltyson commented 1 month ago

This image.sc issue led me to do some digging, and it looks like:

However, the meshes don't seem be centered. I'm not 100% sure what that means TBH, as I don't know exactly what the coordinate system is that they're in. However, when the meshes are cut down the midline by vedo (via brainrender), you don't get exactly half. To reproduce:

from brainrender import Scene
from brainrender import settings
settings.SHADER_STYLE = "plastic"
scene = Scene(atlas_name="allen_cord_20um")
scene.add_brain_region("WM", hemisphere="left")
scene.render()

Gives: Screenshot 2024-07-24 at 10 21 04

This then seems to cause the downstream issues in brainrender-heatmap. Not sure if other atlas have this issue.

imagesc-bot commented 1 month ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/allen-spinal-cord-atlas-is-off-axis/99539/2

IgorTatarnikov commented 3 weeks ago

Currently, the left/right split is done by calculating the center_of_mass in for the root mesh in brainrender and taking that as the midpoint. Not sure why that's the case for this specific atlas. As far as I can tell it's symmetric.

See: https://github.com/brainglobe/brainrender/blob/9cd07c8ad33fcbed0c8a5e396f9b330a5634603e/brainrender/scene.py#L287-L312

For some reason the center_of_mass doesn't align with the geometric? center. I can correct this by just taking the centre of the mesh bounds for the root mesh. That fixes this issue for the spinal cord atlas, and doesn't change the functionality for most of the other atlases.

image

However, this breaks this functionality for the mpin_zfish_1um atlas.

Left hemisphere: image

Right hemisphere: image

I noticed that the mpin-zfish_1um atlas is one of the only one that has a hemispheres.tiff. Is that because the hemispheres aren't symmetrical?

Not sure how to proceed, one idea I had was to take the geometric center for atlases that are marked as symmetric and rely on the hemispheres property for the asymmetric atlases.

adamltyson commented 3 weeks ago

I noticed that the mpin-zfish_1um atlas is one of the only one that has a hemispheres.tiff. Is that because the hemispheres aren't symmetrical?

Yep, if they're symmetrical we programmatically generate the hemisphere image, otherwise it's packaged along with the atlas. TBH I don't know if that's correct for this atlas though.

adamltyson commented 3 weeks ago

This specific issue has been closed by https://github.com/brainglobe/brainrender/pull/375, and these issues have been raised to fix specific atlases: