Skip to content

Fix: 2D coords into atlas space - #110

Open
zenWai wants to merge 8 commits into
brainglobe:mainfrom
zenWai:pr/fix/2d-coords
Open

Fix: 2D coords into atlas space#110
zenWai wants to merge 8 commits into
brainglobe:mainfrom
zenWai:pr/fix/2d-coords

Conversation

@zenWai

@zenWai zenWai commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Description

What is this PR

  • Bug fix

Why is this PR needed?

Related to 2D:

What does this PR do?

This PR adds a separate projection step in the Slicer _project_to_2d( ) that:

  • Undoes the brainrender Z-flip on intersection points
  • Projects to 2D with corrected atlas-space M
  • Add example heatmap_2d_subplots_oblique.py

New tests:
test_get_coordinates.py

  • Confirms mesh contour coords are within 75µm of atlas annotation
  • tuple orientation (1,0,0) produces same coords as "frontal", etc.
  • oblique orientations (0,1,1), (1,0,1), (0.3,0.7,1) produce spread on both 2D axes(Confirms that axis don't go flat due to Z)

test_slicer_2d_example.py

  • runs the slicer_2D.py example end-to-end, verifies region contours are drawn on top of the brain image

New example:
heatmap_2d_subplots_oblique.py

The get_projections( ) method is preserved for anyone using plane centered coordinates and doc updated.

References

How has this PR been tested?

  • New tests
  • New example
  • A custom plan.py example-like to confirm every plane0 projections on 3D match 2D new example images.

Is this a breaking change?

Yes ✔
Expectations of get_structures_slice_coords() changes:

  • Code that negated Y coordinates to compensate (like slicer_2D.py did with -cont[:, 1]) will need to remove that negation
  • Coordinates are not centered with brain center of mass on named orientations[bug fix]
  • Coordinates are not centered with plane center on tuple orientations[bug fix]

Does this PR require an update to the documentation?

No

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

- BR coords to atlas space
- Remove coord negation in slicer_2D example
- logic moved in-line to Slicer.get_structures_slice_coords
- checks, mesh coords are correct
- checks, tuple orientation coords(1, 0, 0), etc. VS named orientation
- checks, ax.patches are drawn on ax.images
- runs test directly with runpy
@codecov

codecov Bot commented Feb 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.50%. Comparing base (0fea8e1) to head (a2f1a59).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #110      +/-   ##
==========================================
+ Coverage   69.63%   77.50%   +7.86%     
==========================================
  Files           5        5              
  Lines         326      360      +34     
==========================================
+ Hits          227      279      +52     
+ Misses         99       81      -18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zenWai zenWai changed the title [WIP] Fix 2D projection Fix: 2D coords into atlas space Feb 23, 2026
@zenWai
zenWai marked this pull request as ready for review February 23, 2026 15:56
@zenWai

zenWai commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

@IgorTatarnikov It closes your issues, would be great to get your review and see if the coords are as expected or something still broken. tysm

@IgorTatarnikov
IgorTatarnikov self-requested a review February 23, 2026 16:01

@IgorTatarnikov IgorTatarnikov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zenWai, apologies it took so long for me to look at this.

This looks great! The axis aligned slicing now returns the correct positions.

However, for the oblique case, some of the axes end up displaying as negative. This should not be the case if we're referring to the real world anatomical coordinates. See below for a screenshot.

Image

Comment on lines +144 to +154
projected = {}
for actor in regions:
intersection = self.plane0.intersect_with(actor._mesh)
if not intersection.vertices.shape[0]:
continue
pieces = intersection.split()
for piece_n, piece in enumerate(pieces):
points = piece.join(reset=True).vertices
projected[actor.name + f"_segment_{piece_n}"] = (
self._project_to_2d(points)
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to avoid duplicating this with the function that already exists in plane.py?

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

Successfully merging this pull request may close these issues.

[BUG] slicer_2D.py example is broken [BUG] Axes generated by brainglobe-heatmap are potentially wrong

2 participants