RoccoDAnt / napari-zelda

ZELDA: a 3D Image Segmentation and Parent to Child relation plugin for microscopy image analysis in napari
BSD 3-Clause "New" or "Revised" License
18 stars 3 forks source link

eigenvalues calculation #9

Open margaretcondep opened 1 month ago

margaretcondep commented 1 month ago

Hi, I am running the "Segment two object populations and relate Parent to Child" protocol for one nuclei and corresponding RNA image. When I click "Relate and Measure", I get this error:

`<skimage.measure._regionprops.RegionProperties object at 0x3a8204fd0>] column_buffer = array([0.00000e+000, 1.16699e+000, ..., 3.89789e-310, 3.89832e-310]) i = 5 regions[i] = <skimage.measure._regionprops.RegionProperties object at 0x43964d130> 856 out[orig_prop] = np.copy(column_buffer) 857 else: 858 # precompute property column names and locations

File ~/anaconda3/envs/napari/lib/python3.9/site-packages/skimage/measure/_regionprops.py:723, in RegionProperties.getitem(self=, key='axis_minor_length') 722 def getitem(self, key): --> 723 value = getattr(self, key, None) self = <skimage.measure._regionprops.RegionProperties object at 0x43964d130> key = 'axis_minor_length' 724 if value is not None: 725 return value

File ~/anaconda3/envs/napari/lib/python3.9/site-packages/skimage/measure/_regionprops.py:574, in RegionProperties.axis_minor_length(self=) 571 elif self._ndim == 3: 572 # equivalent to _inertia_eigvals_to_axes_lengths_3D(ev)[-1] 573 ev = self.inertia_tensor_eigvals --> 574 return sqrt(10 * (-ev[0] + ev[1] + ev[2])) ev = [4.2975, 3.479680712884784, 0.8178192871152158] ev[2] = 0.8178192871152158 ev[1] = 3.479680712884784 ev[0] = 4.2975 575 else: 576 raise ValueError("axis_minor_length only available in 2D and 3D")

EmitLoopError:

While emitting signal 'magicgui.widgets.PushButton.changed', a ValueError occurred in a callback:

Signal emitted at: /Users/margaretconde/anaconda3/envs/napari/lib/python3.9/site-packages/magicgui/widgets/bases/_value_widget.py:71, in _on_value_change

self.changed.emit(value)

Callback error at: /Users/margaretconde/anaconda3/envs/napari/lib/python3.9/site-packages/skimage/measure/_regionprops.py:574, in axis_minor_length

return sqrt(10 * (-ev[0] + ev[1] + ev[2]))

Local variables:
   ev = [4.2975, 3.479680712884784, 0.8178192871152158]`
RoccoDAnt commented 1 month ago

Hi @margaretcondep, I've checked and this error is caused by skimage.measure when small objects are measured, as you can see here: https://github.com/scikit-image/scikit-image/issues/6630

I have implemented a workaround that measures regions one by one and when the minor axis length measurement gives the error caused by scikit-image (because too small), it substitutes the value with zero.

This allows measuring all the other properties of RNA spots, or small child objects in general, avoiding the error and completing the measurement process, to get the results written in the .csv table. I think this should close this issue. Please let me know whether it helps with your analysis.