Skip to content

feat(roimanager): add a tool for creating rectangular rois - #142

Open
ehennestad wants to merge 2 commits into
devfrom
feat-rectangular-roi-tools
Open

ehennestad wants to merge 2 commits into
devfrom
feat-rectangular-roi-tools

Conversation

@ehennestad

Copy link
Copy Markdown
Collaborator

Roimanager can create circular, polygonal and freehand rois, but not rectangular ones, and nansen.stack.crop takes a rectangle that there has been no interactive way to pick. This adds a rectangle tool built the same way as the circle tool, plus the small pieces needed to use it from outside roimanager.

roimanager.pointerTool.rectangleSelect mirrors circleSelect: it draws a rectangle at the pointer, creates a roi centered on the point that is clicked, and changes size with the g and h keys, with shift for the y-direction only.

roimanager.roiMap/createRectangularRoi creates the roi as a polygon with whole-pixel corners. A rectangle that does not fit where it was clicked is moved inside the image and keeps the size the user picked, rather than being cut down to whatever fits, which would otherwise leave rois too small to be useful. A rectangle larger than the image is cut down to the image.

imviewer.plugin.RegionSelector is a small plugin that owns a roi group and a roi map, registers the two pointer tools, and gives the placed rectangles back as an N-by-4 array. It exists because PointerManager is scoped to imviewer and its plugins, so a plain function cannot reach it.

nansen.stack.selectRectangularRegions is the entry point: it opens an ImageStack in imviewer, lets the user place rectangles, and returns them when enter is pressed, or reports that the selection was aborted on escape or if the window is closed. The default rectangle is one sixth of the image, and an earlier selection can be passed in to adjust it.

Tests are in nansen.unittest.roimanager.RectangularRoiTest and cover where a rectangle lands for a given point, the two edge cases and the oversize case, and the size the pointer tool creates rois with. They run headless on an invisible figure, with a struct standing in for the image viewer, since the roi map only needs the image size from it. The interactive part, placing rois by clicking, is not covered and needs a mouse.

🤖 Generated with Claude Code

Roimanager can create circular, polygonal and freehand rois, but not
rectangular ones, and nansen.stack.crop takes a rectangle that there
was no interactive way to pick.

This adds the pieces for that, following how circleSelect works:

- roimanager.pointerTool.rectangleSelect shows a rectangle at the
  pointer and creates a roi where it is clicked. The g and h keys
  change its size, with shift for the y-direction only.
- roimanager.roiMap/createRectangularRoi creates the roi as a polygon
  with whole-pixel corners. A rectangle that does not fit where it was
  clicked is moved inside the image and keeps its size.
- imviewer.plugin.RegionSelector holds the rois in a roi map and gives
  the placed rectangles back.
- nansen.stack.selectRectangularRegions opens a stack in imviewer and
  returns the rectangles the user places, finishing on enter.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

381 tests   381 ✅  44s ⏱️
 26 suites    0 💤
  1 files      0 ❌

Results for commit 9ed4a2d.

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.

1 participant