segmenteverygrain icon indicating copy to clipboard operation
segmenteverygrain copied to clipboard

Interactive interface update

Open dirtbirb opened this issue 8 months ago • 1 comments

Contains a new interactive interface (per #20), defined in a submodule that can be imported as segmenteverygrain.interactions. The base segmenteverygrain module is unchanged.

The new submodule implements a Grain class to keep track of or modify each grain, a GrainPlot class to construct and manage the interactive interface, and some helper functions to handle measurement and I/O.

Also added an example notebook, Segment_every_grain_interactions.ipynb, an updated version of Segment_every_grain.ipynb that has the interactive portion and some saving functions replaced to use the new submodule.

There's a lot of code here, so please let me know if I can better explain or edit anything to make it useful! Some highlights of the new interactive plot:

  • Faster with lots of grains (only blits modified grains to the screen, treats others as background)
  • Faster with large images (uses a downscaled version of large images as the background while still performing measurements on the full-resolution image), tested with orthomosaics > 100 MB
  • Adds more control over grain detection (multiple foreground/background prompts and/or box selection)
  • Allows create / merge / delete / scale operations all in one interface

One possibly important note: the grain property calculations used in the plot don't rely entirely on regionprops_table, which seemed to go from a polygon to a rastered image and back to a polygon before measurement. My new version calculates everything it can from the polygon shape itself, only using a rastered mask for color channel calculations. It agrees pretty closely with the previous method, and naively I expect this could be more accurate. Either way, it's definitely faster (roughly 8x on the Torrey Pines image, likely more improvement on larger images). The previous measurement method is still implemented by using Grain.measure(raster=True), but that option isn't really exposed. I can expose it as some kind of module-level switch (or a GrainPlot parameter?) if that would be useful.

This is the updated version of #22, where I caused some Git troubles for myself by trying to update my name in the history. Ought to be fixed in this version along with updates since then.

dirtbirb avatar Apr 18 '25 21:04 dirtbirb

Thanks a lot @dirtbirb! Give me a bit of time so that first I can work on the issues raised by the reviewers of the JOSS paper and I hope to look at this and merge your changes after that process is over.

zsylvester avatar Apr 23 '25 16:04 zsylvester

Closing this to open a new pull request

dirtbirb avatar Jun 18 '25 02:06 dirtbirb