jamesdolezal / slideflow

Deep learning library for digital pathology, with both Tensorflow and PyTorch support.
https://slideflow.dev
GNU General Public License v3.0
234 stars 39 forks source link

[BUG] Slideflow Studio crashes when doing ROIs #288

Closed skochanny closed 11 months ago

skochanny commented 1 year ago

Description

Slideflow Studio crashes when creating ROIs sometimes. Specifically, when right-clicking only once, without dragging. It causes a rasterio ValueError and the program crashes.

To Reproduce

Steps to reproduce the behavior: I open Studio, I load in a slide (TIFF), I go to the ROI screen and click "Add ROI". If I click and then drag to create the ROI, it works fine. However, if I do not first drag-click and only do a single right click, the program crashes with the following error:

[16:28:53] INFO Loading /home/pearsonlab/PROJECTS/CHRONIC_ENDOMETRITIS/Control_1.tiff
[16:29:13] WARNING Unable to use ROI 0 for Control_1. At least 3 points required to create a shape.
Traceback (most recent call last): File "/home/pearsonlab/anaconda3/envs/sfcell/bin/slideflow-studio", line 366, in main() File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/click/core.py", line 1130, in call return self.main(args, kwargs) File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/click/core.py", line 760, in invoke return __callback(args, kwargs) File "/home/pearsonlab/anaconda3/envs/sfcell/bin/slideflow-studio", line 83, in main viz.run() File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/studio/gui/_glfw.py", line 167, in run self.draw_frame() File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/studio/init.py", line 1166, in draw_frame self._draw_control_pane() File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/studio/init.py", line 325, in _draw_control_pane self.sidebar.draw() File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/studio/init.py", line 1857, in draw viz.slide_widget(self.expanded and self.selected == 'slide') File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/studio/gui/imgui_utils.py", line 160, in decorator res = method(self, *args, *kwargs) File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/studio/widgets/slide.py", line 709, in call self._process_roi_capture() File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/studio/widgets/slide.py", line 243, in _process_roi_capture viz.wsi.load_roi_array(wsi_coords) File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/slide/init.py", line 1875, in load_roi_array self.process_rois() File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/slide/init.py", line 2071, in process_rois self._build_coord() File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/slideflow/slide/init.py", line 1247, in _build_coord self.roi_mask = rasterio.features.rasterize( File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/rasterio/env.py", line 401, in wrapper return f(args, kwds) File "/home/pearsonlab/anaconda3/envs/sfcell/lib/python3.8/site-packages/rasterio/features.py", line 327, in rasterize raise ValueError('No valid geometry objects found for rasterize') ValueError: No valid geometry objects found for rasterize

I think it has something to do with not having any shapes it can reference in context with the single right click. Of note, if I have drawn other ROIs first, and then right click (in the below output I right-clicked multiple times) there also seems to be a strange warning error. Studio currently, I think, just doesn't like single-click annotations. It seems to be logging every right click as an ROI shape and runs into some kind of issue/problem when dealing with single-clicks.

[16:26:44] WARNING Unable to use ROI 5 for Control_1. At least 3 points required to create a shape.
[16:27:19] WARNING Unable to use ROI 4 for Control_1. At least 3 points required to create a shape.
[16:27:31] WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
[16:27:41] WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
[16:27:48] WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
[16:27:49] WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 6 for Control_1. At least 3 points required to create a shape.
[16:27:51] WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 6 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 7 for Control_1. At least 3 points required to create a shape.
[16:27:55] WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 6 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 7 for Control_1. At least 3 points required to create a shape.
[16:27:56] WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 6 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 7 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 9 for Control_1. At least 3 points required to create a shape.
[16:27:57] WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 6 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 7 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 9 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 10 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 6 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 7 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 9 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 10 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 11 for Control_1. At least 3 points required to create a shape.
[16:27:58] WARNING Unable to use ROI 3 for Control_1. At least 3 points required to create a shape.
WARNING Unable to use ROI 6 for Control_1. At least 3 points required to create a shape.

Expected behavior

It shouldn't crash. It could either log the ROI as an individual point (might be nice feature, QuPath has that option, but you must select the "Points" tool instead of the "Polygon" tool). Or, really I would like it to ignore single-click ROIs completely.

Environment:

jamesdolezal commented 1 year ago

Thanks Sara - I've just pushed an update to dev-2.1 that should fix this issue. Let me know if it resolves the problem on your end, as well.

jamesdolezal commented 11 months ago

Fixed in 0c158549cb4b8f0a25f113b914367d999948e1e7