napari-plot-profile icon indicating copy to clipboard operation
napari-plot-profile copied to clipboard

ValueError: operands could not be broadcast together with shapes (3,) (2,)

Open ajasja opened this issue 1 year ago • 4 comments

Hi,

This is excellent functionality (I'm evaluating if I can switch from FIJI:)

However when I open an image, draw a line and run the plugin, I get a ValueError: operands could not be broadcast together with shapes (3,) (2,) exception image

Env info:

  • napari: 0.4.18

  • Platform: Windows-10-10.0.19045-SP0

  • Python: 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:29:51) [MSC v.1929 64 bit (AMD64)]

  • Qt: 5.15.2

  • PyQt5: 5.15.4

  • NumPy: 1.25.2

  • SciPy: 1.9.3

  • Dask: 2022.11.0

  • VisPy: 0.12.2

  • magicgui: 0.6.0

  • superqt: 0.6.1

  • in-n-out: 0.1.6

  • app-model: 0.1.1

  • npe2: 0.6.1

Full traceback is here:

ValueError Traceback (most recent call last) File C:\bin\python\anaconda64\envs\py10image\lib\site-packages\napari_qt\menus\plugins_menu.py:105, in PluginsMenu._add_plugin_actions.._add_toggle_widget(key=('napari-plot-profile', 'Plot Profile'), hook_type='dock') 102 return 104 if hook_type == 'dock': --> 105 self._win.add_plugin_dock_widget(*key) key = ('napari-plot-profile', 'Plot Profile') self._win = <napari._qt.qt_main_window.Window object at 0x000001FD51760580> self = <napari._qt.menus.plugins_menu.PluginsMenu object at 0x000001FD61182170> 106 else: 107 self._win._add_plugin_function_widget(*key)

File C:\bin\python\anaconda64\envs\py10image\lib\site-packages\napari_qt\qt_main_window.py:811, in Window.add_plugin_dock_widget(self=<napari._qt.qt_main_window.Window object>, plugin_name='napari-plot-profile', widget_name='Plot Profile', tabify=False) 808 wdg = wdg._magic_widget 809 return dock_widget, wdg --> 811 wdg = _instantiate_dock_widget( Widget = <class 'napari_plot_profile._dock_widget.PlotProfile'> self = <napari._qt.qt_main_window.Window object at 0x000001FD51760580> 812 Widget, cast('Viewer', self._qt_viewer.viewer) 813 ) 815 # Add dock widget 816 dock_kwargs.pop('name', None)

File C:\bin\python\anaconda64\envs\py10image\lib\site-packages\napari_qt\qt_main_window.py:1465, in _instantiate_dock_widget(wdg_cls=<class 'napari_plot_profile._dock_widget.PlotProfile'>, viewer=Viewer(camera=Camera(center=(0.0, 265.5, 270.5),...ouse_drag_gen={}, _mouse_wheel_gen={}, keymap={})) 1460 break 1461 # cannot look for param.kind == param.VAR_KEYWORD because 1462 # QWidget allows **kwargs but errs on unknown keyword arguments 1463 1464 # instantiate the widget -> 1465 return wdg_cls(**kwargs) kwargs = {'napari_viewer': Viewer(camera=Camera(center=(0.0, 265.5, 270.5), zoom=1.707950148809524, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=False, mouse_zoom=True), cursor=Cursor(position=(4.075508866833751, -126.7598387528613), scaled=True, size=1, style=<CursorStyle.CROSS: 'cross'>), dims=Dims(ndim=2, ndisplay=2, last_used=0, range=((0.0, 532.0, 1.0), (0.0, 542.0, 1.0)), current_step=(265, 270), order=(0, 1), axis_labels=('0', '1')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer '20231115-172120_WT' at 0x1fd6120f9d0>, <Shapes layer 'Shapes' at 0x1fd54355780>], help='use <6> for pan/zoom, use <2> for transform, use <R> for add rectangles, use <E> for add ellipses, use <T> for add path, use <P> for add polygons, use <Shift-P> for add polygons lasso, use <4> for select vertices, use <5> for select shapes, use <2> for insert vertex, use <1> for remove vertex', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x000001FD50C0BE20>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={})} wdg_cls = <class 'napari_plot_profile._dock_widget.PlotProfile'>

File C:\bin\python\anaconda64\envs\py10image\lib\site-packages\napari_plot_profile_dock_widget.py:121, in PlotProfile.init(self=<napari_plot_profile._dock_widget.PlotProfile object>, napari_viewer=Viewer(camera=Camera(center=(0.0, 265.5, 270.5),...ouse_drag_gen={}, _mouse_wheel_gen={}, keymap={})) 117 self._timer.stop() 119 self._timer.start() --> 121 self.redraw() self = <napari_plot_profile._dock_widget.PlotProfile object at 0x000001FD547FF9A0>

File C:\bin\python\anaconda64\envs\py10image\lib\site-packages\napari_plot_profile_dock_widget.py:196, in PlotProfile.redraw(self=<napari_plot_profile._dock_widget.PlotProfile object>, force_redraw=False) 193 self._data = [] 194 for i, layer in enumerate(self.selected_image_layers()): 195 # plot profile --> 196 my_profile = profile(layer, line, num_points=num_bins) line = <class 'numpy.ndarray'> (2, 2) float64 num_bins = 100 layer = <Image layer '20231115-172120_WT' at 0x1fd6120f9d0> 197 my_profile['name'] = layer.name 198 self._data.append(my_profile)

File C:\bin\python\anaconda64\envs\py10image\lib\site-packages\napari_plot_profile_dock_widget.py:272, in profile(layer=<Image layer '20231115-172120_WT'>, line=<class 'numpy.ndarray'> (2, 2) float64, num_points=100) 270 # check if point still within image 271 position_clipped = np.maximum(position, np.zeros(position.shape)) --> 272 position_clipped = np.minimum(position_clipped, layer.data.shape - np.ones(position.shape)) position = <class 'numpy.ndarray'> (2,) float64 position_clipped = <class 'numpy.ndarray'> (2,) float64 layer = <Image layer '20231115-172120_WT' at 0x1fd6120f9d0> np.minimum = <ufunc 'minimum'> np = <module 'numpy' from 'C:\bin\python\anaconda64\envs\py10image\lib\site-packages\numpy\init.py'> 273 if np.array_equal(position, position_clipped): 274 position = position.astype(int)

ValueError: operands could not be broadcast together with shapes (3,) (2,)

ajasja avatar Dec 12 '23 14:12 ajasja

Hi @ajasja ,

I'm suspecting it has something to do with the data you are looking at. Can you share some details about the data (is it RGB?) or even share the dataset? That would make it easier to debug the issue.

Thanks!

Best, Robert

haesleinhuepf avatar Dec 12 '23 15:12 haesleinhuepf

Thank you for your quick response! Here is an example image: (Zipped TIF). 20231117-102700_WT.zip

image

Hmm I guess it might indeed be RGB (although the other channels are off).

Best, Ajasja

ajasja avatar Dec 13 '23 12:12 ajasja

I confirm there is this issue present when doing linouts of RGB images. For instance failed with RGB .png or .jpeg image.

Image

while it worked with a grayscale .tiff image (as in the docs folder)

Image

rth avatar Apr 15 '25 14:04 rth

Hi @rth ,

would you mind splitting the RGB image using the right-click menu?

It should then work aftwards.

Image

haesleinhuepf avatar Apr 16 '25 13:04 haesleinhuepf