haesleinhuepf / napari-accelerated-pixel-and-object-classification

GPU-accelerated, OpenCL-based Random Forest Classifiers for pixel and labeled object classification in napari.
BSD 3-Clause "New" or "Revised" License
43 stars 7 forks source link

Object segmentation error #41

Closed milenovic closed 1 year ago

milenovic commented 1 year ago

Hello,

I am attempting to give a try to napari-APOC to segment nuclei from confocal microscopy image. I opened my image, created a new label layer and marked two classes (nuclei and background with paint brush tool. Then Tools -> Segmentation / labeling -> Object Segmentation (APOC). You can see my settings and labelled image here: Napari-screenshot1

When I press Train after some time I get the following error on the conda console:

train ObjectSegmenter
num images 1
object annotation value 1
features gaussian_blur=1 difference_of_gaussian=1 laplace_box_of_gaussian_blur=1 sobel_of_gaussian_blur=1
depth 2
num trees 100
file C:/Users/milan/Documents/data/napari/ObjectSegmenter.cl
annotation shape (2396, 2396)
Training done. Applying model...
Applying / prediction done.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~\anaconda3\envs\Napari\lib\site-packages\napari\utils\events\containers\_typed.py:140, in TypedMutableSequence.__getitem__(self=[<Image layer 'Ch1' at 0x1fb18905e50>, <Labels layer 'Labels' at 0x1fb18158460>], key='Result of ObjectSegmenter.cl')
    139 try:
--> 140     return self.__getitem__(self.index(key))
        key = 'Result of ObjectSegmenter.cl'
        self = [<Image layer 'Ch1' at 0x1fb18905e50>, <Labels layer 'Labels' at 0x1fb18158460>]
    141 except ValueError as e:

File ~\anaconda3\envs\Napari\lib\site-packages\napari\utils\events\containers\_typed.py:228, in TypedMutableSequence.index(self=[<Image layer 'Ch1' at 0x1fb18905e50>, <Labels layer 'Labels' at 0x1fb18158460>], value='Result of ObjectSegmenter.cl', start=0, stop=None)
    226         return i
--> 228 raise ValueError(
        trans = <napari.utils.translations.TranslationBundle object at 0x000001FB7FDDAC70>
        value = 'Result of ObjectSegmenter.cl'
    229     trans._(
    230         "{value!r} is not in list",
    231         deferred=True,
    232         value=value,
    233     )
    234 )

ValueError: 'Result of ObjectSegmenter.cl' is not in list

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
File ~\anaconda3\envs\Napari\lib\site-packages\napari_accelerated_pixel_and_object_classification\_dock_widget.py:564, in _add_to_viewer(viewer=Viewer(axes=Axes(visible=False, labels=True, col...._transform_active_layer at 0x000001FB20D5C0D0>}), as_image=False, name='Result of ObjectSegmenter.cl', data=<class 'numpy.ndarray'> (2396, 2396) uint32, scale=<class 'numpy.ndarray'> (4,) float64)
    563 try:
--> 564     viewer.layers[name].data = data.astype(int)
        viewer.layers = [<Image layer 'Ch1' at 0x1fb18905e50>, <Labels layer 'Labels' at 0x1fb18158460>]
        name = 'Result of ObjectSegmenter.cl'
        data = <class 'numpy.ndarray'> (2396, 2396) uint32
        viewer = Viewer(axes=Axes(visible=False, labels=True, colored=True, dashed=False, arrows=True), camera=Camera(center=(0.0, 106.78394968933084, 123.09780240603472), zoom=3.482926406502374, angles=(0.0, 0.0, 90.0), perspective=0.0, interactive=False), cursor=Cursor(position=(0.0, 0.0, 197.65581185467153, 122.38001617146018), scaled=True, size=3, style=<CursorStyle.CIRCLE: 'circle'>), dims=Dims(ndim=4, ndisplay=2, last_used=0, range=((0.0, 1.0, 1.0), (0.0, 1.0, 1.0), (0.0, 212.5480501667428, 0.08870953679747196), (0.0, 212.5480501667428, 0.08870953679747196)), current_step=(0, 0, 1198, 1198), order=(0, 1, 2, 3), axis_labels=('0', '1', '2', '3')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'Ch1' at 0x1fb18905e50>, <Labels layer 'Labels' at 0x1fb18158460>], scale_bar=ScaleBar(visible=False, colored=False, color=<class 'numpy.ndarray'> (4,) float32, ticks=True, position=<Position.BOTTOM_RIGHT: 'bottom_right'>, font_size=10.0, box=False, box_color=<class 'numpy.ndarray'> (4,) float32, unit=None), text_overlay=TextOverlay(visible=False, color=<class 'numpy.ndarray'> (4,) float32, font_size=10.0, position=<TextOverlayPosition.TOP_LEFT: 'top_left'>, text=''), overlays=Overlays(interaction_box=InteractionBox(points=None, show=False, show_handle=False, show_vertices=False, selection_box_drag=None, selection_box_final=None, transform_start=<napari.utils.transforms.transforms.Affine object at 0x000001FB180F80A0>, transform_drag=<napari.utils.transforms.transforms.Affine object at 0x000001FB180F8100>, transform_final=<napari.utils.transforms.transforms.Affine object at 0x000001FB180F8160>, transform=<napari.utils.transforms.transforms.Affine object at 0x000001FB1AAE3070>, allow_new_selection=True, selected_vertex=None)), help='use <1> for activate the label eraser, use <3> for activate the fill bucket, use <4> for pick mode, use <5> for pan/zoom mode', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_move at 0x000001FB20D9BE50>], mouse_drag_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_drag at 0x000001FB20D5C430>], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x000001FB17572790>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Shift': <function InteractionBoxMouseBindings.initialize_key_events.<locals>.hold_to_lock_aspect_ratio at 0x000001FB20D5C280>, 'Control-Shift-R': <function InteractionBoxMouseBindings._reset_active_layer_affine at 0x000001FB20D5C040>, 'Control-Shift-A': <function InteractionBoxMouseBindings._transform_active_layer at 0x000001FB20D5C0D0>})
    565     viewer.layers[name].visible = True

File ~\anaconda3\envs\Napari\lib\site-packages\napari\utils\events\containers\_typed.py:142, in TypedMutableSequence.__getitem__(self=[<Image layer 'Ch1' at 0x1fb18905e50>, <Labels layer 'Labels' at 0x1fb18158460>], key='Result of ObjectSegmenter.cl')
    141     except ValueError as e:
--> 142         raise KeyError(str(e)) from e
    144 result = self._list[key]

KeyError: "'Result of ObjectSegmenter.cl' is not in list"

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
File ~\anaconda3\envs\Napari\lib\site-packages\napari_accelerated_pixel_and_object_classification\_dock_widget.py:161, in ObjectSegmentation.__init__.<locals>.train_clicked(*arg=(False,), **kwargs={})
    157     return
    159 first_image_layer = self.get_selected_images()[0]
--> 161 self.train(
        self = <napari_accelerated_pixel_and_object_classification._dock_widget.ObjectSegmentation object at 0x000001FB23B82670>
        num_object_annotation_spinner = <PyQt5.QtWidgets.QSpinBox object at 0x000001FB23BBD040>
        self.feature_selector = <napari_accelerated_pixel_and_object_classification._dock_widget.FeatureSelector object at 0x000001FB23BBD550>
        num_max_depth_spinner = <PyQt5.QtWidgets.QSpinBox object at 0x000001FB28BD4EE0>
        num_trees_spinner = <PyQt5.QtWidgets.QSpinBox object at 0x000001FB28BD4F70>
        filename_edit = FileEdit(mode='w', value=WindowsPath('C:/Users/milan/Documents/data/napari/ObjectSegmenter.cl'))
        show_classifier_statistics_checkbox = <PyQt5.QtWidgets.QCheckBox object at 0x000001FB28BDA280>
        first_image_layer = <Image layer 'Ch1' at 0x1fb18905e50>
    162     self.get_selected_images_data(),
    163     self.get_selected_annotation_data(),
    164     num_object_annotation_spinner.value(),
    165     self.feature_selector.getFeatures(),
    166     num_max_depth_spinner.value(),
    167     num_trees_spinner.value(),
    168     str(filename_edit.value.absolute()).replace("\\", "/").replace("//", "/"),
    169     show_classifier_statistics_checkbox.isChecked(),
    170     first_image_layer.scale
    171 )

File ~\anaconda3\envs\Napari\lib\site-packages\napari_accelerated_pixel_and_object_classification\_dock_widget.py:297, in ObjectSegmentation.train(self=<napari_accelerated_pixel_and_object_classification._dock_widget.ObjectSegmentation object>, images=<class 'numpy.ndarray'> (2396, 2396) uint16, annotation=<class 'numpy.ndarray'> (2396, 2396) int32, object_annotation_value=1, feature_definition='gaussian_blur=1 difference_of_gaussian=1 laplace_box_of_gaussian_blur=1 sobel_of_gaussian_blur=1', num_max_depth=2, num_trees=100, filename='C:/Users/milan/Documents/data/napari/ObjectSegmenter.cl', show_classifier_statistics=True, scale=<class 'numpy.ndarray'> (4,) float64)
    294 print("Applying / prediction done.")
    296 short_filename = filename.split("/")[-1]
--> 297 _add_to_viewer(self.viewer, self.classifier_class == ProbabilityMapper, "Result of " + short_filename, result, scale)
        result = <class 'numpy.ndarray'> (2396, 2396) uint32
        short_filename = 'ObjectSegmenter.cl'
        self.classifier_class = <class 'apoc._object_segmenter.ObjectSegmenter'>
        self.viewer = Viewer(axes=Axes(visible=False, labels=True, colored=True, dashed=False, arrows=True), camera=Camera(center=(0.0, 106.78394968933084, 123.09780240603472), zoom=3.482926406502374, angles=(0.0, 0.0, 90.0), perspective=0.0, interactive=False), cursor=Cursor(position=(0.0, 0.0, 197.65581185467153, 122.38001617146018), scaled=True, size=3, style=<CursorStyle.CIRCLE: 'circle'>), dims=Dims(ndim=4, ndisplay=2, last_used=0, range=((0.0, 1.0, 1.0), (0.0, 1.0, 1.0), (0.0, 212.5480501667428, 0.08870953679747196), (0.0, 212.5480501667428, 0.08870953679747196)), current_step=(0, 0, 1198, 1198), order=(0, 1, 2, 3), axis_labels=('0', '1', '2', '3')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'Ch1' at 0x1fb18905e50>, <Labels layer 'Labels' at 0x1fb18158460>], scale_bar=ScaleBar(visible=False, colored=False, color=<class 'numpy.ndarray'> (4,) float32, ticks=True, position=<Position.BOTTOM_RIGHT: 'bottom_right'>, font_size=10.0, box=False, box_color=<class 'numpy.ndarray'> (4,) float32, unit=None), text_overlay=TextOverlay(visible=False, color=<class 'numpy.ndarray'> (4,) float32, font_size=10.0, position=<TextOverlayPosition.TOP_LEFT: 'top_left'>, text=''), overlays=Overlays(interaction_box=InteractionBox(points=None, show=False, show_handle=False, show_vertices=False, selection_box_drag=None, selection_box_final=None, transform_start=<napari.utils.transforms.transforms.Affine object at 0x000001FB180F80A0>, transform_drag=<napari.utils.transforms.transforms.Affine object at 0x000001FB180F8100>, transform_final=<napari.utils.transforms.transforms.Affine object at 0x000001FB180F8160>, transform=<napari.utils.transforms.transforms.Affine object at 0x000001FB1AAE3070>, allow_new_selection=True, selected_vertex=None)), help='use <1> for activate the label eraser, use <3> for activate the fill bucket, use <4> for pick mode, use <5> for pan/zoom mode', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_move at 0x000001FB20D9BE50>], mouse_drag_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_drag at 0x000001FB20D5C430>], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x000001FB17572790>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Shift': <function InteractionBoxMouseBindings.initialize_key_events.<locals>.hold_to_lock_aspect_ratio at 0x000001FB20D5C280>, 'Control-Shift-R': <function InteractionBoxMouseBindings._reset_active_layer_affine at 0x000001FB20D5C040>, 'Control-Shift-A': <function InteractionBoxMouseBindings._transform_active_layer at 0x000001FB20D5C0D0>})
        "Result of " + short_filename = 'Result of ObjectSegmenter.cl'
        scale = <class 'numpy.ndarray'> (4,) float64
        self = <napari_accelerated_pixel_and_object_classification._dock_widget.ObjectSegmentation object at 0x000001FB23B82670>
    299 if show_classifier_statistics and self.viewer is not None:
    300     table = QTableWidget()

File ~\anaconda3\envs\Napari\lib\site-packages\napari_accelerated_pixel_and_object_classification\_dock_widget.py:570, in _add_to_viewer(viewer=Viewer(axes=Axes(visible=False, labels=True, col...._transform_active_layer at 0x000001FB20D5C0D0>}), as_image=False, name='Result of ObjectSegmenter.cl', data=<class 'numpy.ndarray'> (2396, 2396) uint32, scale=<class 'numpy.ndarray'> (4,) float64)
    568     viewer.add_image(data, name=name, scale=scale)
    569 else:
--> 570     viewer.add_labels(data.astype(int), name=name, scale=scale)
        name = 'Result of ObjectSegmenter.cl'
        data = <class 'numpy.ndarray'> (2396, 2396) uint32
        viewer = Viewer(axes=Axes(visible=False, labels=True, colored=True, dashed=False, arrows=True), camera=Camera(center=(0.0, 106.78394968933084, 123.09780240603472), zoom=3.482926406502374, angles=(0.0, 0.0, 90.0), perspective=0.0, interactive=False), cursor=Cursor(position=(0.0, 0.0, 197.65581185467153, 122.38001617146018), scaled=True, size=3, style=<CursorStyle.CIRCLE: 'circle'>), dims=Dims(ndim=4, ndisplay=2, last_used=0, range=((0.0, 1.0, 1.0), (0.0, 1.0, 1.0), (0.0, 212.5480501667428, 0.08870953679747196), (0.0, 212.5480501667428, 0.08870953679747196)), current_step=(0, 0, 1198, 1198), order=(0, 1, 2, 3), axis_labels=('0', '1', '2', '3')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'Ch1' at 0x1fb18905e50>, <Labels layer 'Labels' at 0x1fb18158460>], scale_bar=ScaleBar(visible=False, colored=False, color=<class 'numpy.ndarray'> (4,) float32, ticks=True, position=<Position.BOTTOM_RIGHT: 'bottom_right'>, font_size=10.0, box=False, box_color=<class 'numpy.ndarray'> (4,) float32, unit=None), text_overlay=TextOverlay(visible=False, color=<class 'numpy.ndarray'> (4,) float32, font_size=10.0, position=<TextOverlayPosition.TOP_LEFT: 'top_left'>, text=''), overlays=Overlays(interaction_box=InteractionBox(points=None, show=False, show_handle=False, show_vertices=False, selection_box_drag=None, selection_box_final=None, transform_start=<napari.utils.transforms.transforms.Affine object at 0x000001FB180F80A0>, transform_drag=<napari.utils.transforms.transforms.Affine object at 0x000001FB180F8100>, transform_final=<napari.utils.transforms.transforms.Affine object at 0x000001FB180F8160>, transform=<napari.utils.transforms.transforms.Affine object at 0x000001FB1AAE3070>, allow_new_selection=True, selected_vertex=None)), help='use <1> for activate the label eraser, use <3> for activate the fill bucket, use <4> for pick mode, use <5> for pan/zoom mode', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_move at 0x000001FB20D9BE50>], mouse_drag_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_drag at 0x000001FB20D5C430>], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x000001FB17572790>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Shift': <function InteractionBoxMouseBindings.initialize_key_events.<locals>.hold_to_lock_aspect_ratio at 0x000001FB20D5C280>, 'Control-Shift-R': <function InteractionBoxMouseBindings._reset_active_layer_affine at 0x000001FB20D5C040>, 'Control-Shift-A': <function InteractionBoxMouseBindings._transform_active_layer at 0x000001FB20D5C0D0>})
        scale = <class 'numpy.ndarray'> (4,) float64

File ~\anaconda3\envs\Napari\lib\site-packages\napari\components\viewer_model.py:4, in add_labels(self=Viewer(axes=Axes(visible=False, labels=True, col...._transform_active_layer at 0x000001FB20D5C0D0>}), data=<class 'numpy.ndarray'> (2396, 2396) int32, num_colors=50, features=None, properties=None, color=None, seed=0.5, name='Result of ObjectSegmenter.cl', metadata=None, scale=<class 'numpy.ndarray'> (4,) float64, translate=None, rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', rendering='iso_categorical', depiction='volume', visible=True, multiscale=None, cache=True, plane=None, experimental_clipping_planes=None)
      1 from __future__ import annotations
      3 import inspect
----> 4 import itertools
      5 import os
      6 import warnings

File ~\anaconda3\envs\Napari\lib\site-packages\napari\layers\labels\labels.py:247, in Labels.__init__(self=<class 'napari.layers.labels.labels.Labels'> instance, data=<class 'numpy.ndarray'> (2396, 2396) int32, num_colors=50, features=None, properties=None, color=None, seed=0.5, name='Result of ObjectSegmenter.cl', metadata=None, scale=<class 'numpy.ndarray'> (4,) float64, translate=None, rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', rendering='iso_categorical', depiction='volume', visible=True, multiscale=None, cache=True, plane=None, experimental_clipping_planes=None)
    244 data = self._ensure_int_labels(data)
    245 self._color_lookup_func = None
--> 247 super().__init__(
        data = <class 'numpy.ndarray'> (2396, 2396) int32
        self._random_colormap = Colormap(colors=<class 'numpy.ndarray'> (51, 4) float32, name='label_colormap', interpolation=<ColormapInterpolationMode.ZERO: 'zero'>, controls=<class 'numpy.ndarray'> (52,) float32)
        Exception trying to inspect frame. No more locals available.
    248     data,
    249     rgb=False,
    250     colormap=self._random_colormap,
    251     contrast_limits=[0.0, 1.0],
    252     interpolation2d='nearest',
    253     interpolation3d='nearest',
    254     rendering=rendering,
    255     depiction=depiction,
    256     iso_threshold=0,
    257     name=name,
    258     metadata=metadata,
    259     scale=scale,
    260     translate=translate,
    261     rotate=rotate,
    262     shear=shear,
    263     affine=affine,
    264     opacity=opacity,
    265     blending=blending,
    266     visible=visible,
    267     multiscale=multiscale,
    268     cache=cache,
    269     plane=plane,
    270     experimental_clipping_planes=experimental_clipping_planes,
    271 )
    273 self.events.add(
    274     preserve_labels=Event,
    275     properties=Event,
   (...)
    284     paint=Event,
    285 )
    287 self._feature_table = _FeatureTable.from_layer(
    288     features=features, properties=properties
    289 )

File ~\anaconda3\envs\Napari\lib\site-packages\napari\utils\migrations.py:44, in rename_argument.<locals>._wrapper.<locals>._update_from_dict(*args=<class 'tuple'> instance, **kwargs={'affine': None, 'blending': 'translucent', 'cache': True, 'colormap': Colormap(colors=<class 'numpy.ndarray'> (51, 4) ..., controls=<class 'numpy.ndarray'> (52,) float32), 'contrast_limits': [0.0, 1.0], 'depiction': 'volume', 'experimental_clipping_planes': None, 'interpolation2d': 'nearest', 'interpolation3d': 'nearest', 'iso_threshold': 0, ...})
     42     kwargs = kwargs.copy()
     43     kwargs[to_name] = kwargs.pop(from_name)
---> 44 return func(*args, **kwargs)
        func = <function _ImageBase.__init__ at 0x000001FB1656ED30>
        kwargs = {'rgb': False, 'colormap': Colormap(colors=<class 'numpy.ndarray'> (51, 4) float32, name='label_colormap', interpolation=<ColormapInterpolationMode.ZERO: 'zero'>, controls=<class 'numpy.ndarray'> (52,) float32), 'contrast_limits': [0.0, 1.0], 'interpolation2d': 'nearest', 'interpolation3d': 'nearest', 'rendering': 'iso_categorical', 'depiction': 'volume', 'iso_threshold': 0, 'name': 'Result of ObjectSegmenter.cl', 'metadata': None, 'scale': <class 'numpy.ndarray'> (4,) float64, 'translate': None, 'rotate': None, 'shear': None, 'affine': None, 'opacity': 0.7, 'blending': 'translucent', 'visible': True, 'multiscale': None, 'cache': True, 'plane': None, 'experimental_clipping_planes': None}
        Exception trying to inspect frame. No more locals available.

File ~\anaconda3\envs\Napari\lib\site-packages\napari\layers\image\image.py:277, in _ImageBase.__init__(self=<class 'napari.layers.labels.labels.Labels'> instance, data=<class 'numpy.ndarray'> (2396, 2396) int32, rgb=False, colormap=Colormap(colors=<class 'numpy.ndarray'> (51, 4) ..., controls=<class 'numpy.ndarray'> (52,) float32), contrast_limits=[0.0, 1.0], gamma=1, interpolation2d='nearest', interpolation3d='nearest', rendering='iso_categorical', iso_threshold=0, attenuation=0.05, name='Result of ObjectSegmenter.cl', metadata=None, scale=<class 'numpy.ndarray'> (4,) float64, translate=None, rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', visible=True, multiscale=False, cache=True, depiction='volume', plane=None, experimental_clipping_planes=None)
    274 if rgb:
    275     ndim -= 1
--> 277 super().__init__(
        data = <class 'numpy.ndarray'> (2396, 2396) int32
        ndim = 2
        name = 'Result of ObjectSegmenter.cl'
        metadata = None
        scale = <class 'numpy.ndarray'> (4,) float64
        translate = None
        rotate = None
        shear = None
        affine = None
        opacity = 0.7
        blending = 'translucent'
        visible = True
        multiscale = False
        cache = True
        experimental_clipping_planes = None
    278     data,
    279     ndim,
    280     name=name,
    281     metadata=metadata,
    282     scale=scale,
    283     translate=translate,
    284     rotate=rotate,
    285     shear=shear,
    286     affine=affine,
    287     opacity=opacity,
    288     blending=blending,
    289     visible=visible,
    290     multiscale=multiscale,
    291     cache=cache,
    292     experimental_clipping_planes=experimental_clipping_planes,
    293 )
    295 self.events.add(
    296     mode=Event,
    297     interpolation=WarningEmitter(
   (...)
    309     attenuation=Event,
    310 )
    312 self._array_like = True

File ~\anaconda3\envs\Napari\lib\site-packages\napari\layers\intensity_mixin.py:28, in IntensityVisualizationMixin.__init__(self=<class 'napari.layers.labels.labels.Labels'> instance, *args=(<class 'numpy.ndarray'> (2396, 2396) int32, 2), **kwargs={'affine': None, 'blending': 'translucent', 'cache': True, 'experimental_clipping_planes': None, 'metadata': None, 'multiscale': False, 'name': 'Result of ObjectSegmenter.cl', 'opacity': 0.7, 'rotate': None, 'scale': <class 'numpy.ndarray'> (4,) float64, ...})
     27 def __init__(self, *args, **kwargs):
---> 28     super().__init__(*args, **kwargs)
        args = (<class 'numpy.ndarray'> (2396, 2396) int32, 2)
        kwargs = {'name': 'Result of ObjectSegmenter.cl', 'metadata': None, 'scale': <class 'numpy.ndarray'> (4,) float64, 'translate': None, 'rotate': None, 'shear': None, 'affine': None, 'opacity': 0.7, 'blending': 'translucent', 'visible': True, 'multiscale': False, 'cache': True, 'experimental_clipping_planes': None}
     30     self.events.add(
     31         contrast_limits=Event,
     32         contrast_limits_range=Event,
     33         gamma=Event,
     34         colormap=Event,
     35     )
     36     self._gamma = 1

File ~\anaconda3\envs\Napari\lib\site-packages\napari\layers\base\base.py:294, in Layer.__init__(self=<class 'napari.layers.labels.labels.Labels'> instance, data=<class 'numpy.ndarray'> (2396, 2396) int32, ndim=2, name='Result of ObjectSegmenter.cl', metadata=None, scale=<class 'numpy.ndarray'> (4,) float64, translate=[0, 0], rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', visible=True, multiscale=False, cache=True, experimental_clipping_planes=None)
    289 if translate is None:
    290     translate = [0] * ndim
    291 self._transforms = TransformChain(
    292     [
    293         Affine(np.ones(ndim), np.zeros(ndim), name='tile2data'),
--> 294         CompositeAffine(
        Exception trying to inspect frame. No more locals available.
    295             scale,
    296             translate,
    297             rotate=rotate,
    298             shear=shear,
    299             ndim=ndim,
    300             name='data2physical',
    301         ),
    302         coerce_affine(affine, ndim=ndim, name='physical2world'),
    303         Affine(np.ones(ndim), np.zeros(ndim), name='world2grid'),
    304     ]
    305 )
    307 self._dims_point = [0] * ndim
    308 self.corner_pixels = np.zeros((2, ndim), dtype=int)

File ~\anaconda3\envs\Napari\lib\site-packages\napari\utils\transforms\transforms.py:710, in CompositeAffine.__init__(self=<napari.utils.transforms.transforms.CompositeAffine object>, scale=<class 'numpy.ndarray'> (4,) float64, translate=[0, 0], rotate=None, shear=None, ndim=2, name='data2physical')
    706     ndim = infer_ndim(
    707         scale=scale, translate=translate, rotate=rotate, shear=shear
    708     )
    709 self._translate = translate_to_vector(translate, ndim=ndim)
--> 710 self._scale = scale_to_vector(scale, ndim=ndim)
        scale = <class 'numpy.ndarray'> (4,) float64
        ndim = 2
        self = <napari.utils.transforms.transforms.CompositeAffine object at 0x000001FB1A50E970>
    711 self._rotate = rotate_to_matrix(rotate, ndim=ndim)
    712 self._shear = shear_to_matrix(shear, ndim=ndim)

File ~\anaconda3\envs\Napari\lib\site-packages\napari\utils\transforms\transform_utils.py:137, in scale_to_vector(scale=<class 'numpy.ndarray'> (4,) float64, ndim=2)
    135 scale_arr = np.ones(ndim)
    136 if scale is not None:
--> 137     scale_arr[-len(scale) :] = scale
        scale_arr = <class 'numpy.ndarray'> (2,) float64
        scale = <class 'numpy.ndarray'> (4,) float64
    138 return scale_arr

ValueError: could not broadcast input array from shape (4,) into shape (2,)

Am I doing something wrong?

For reference my Conda environment is:

name: Napari
channels:
  - conda-forge
  - defaults
dependencies:
  - alabaster=0.7.13=pyhd8ed1ab_0
  - aom=3.5.0=h63175ca_0
  - app-model=0.1.4=pyhd8ed1ab_0
  - appdirs=1.4.4=pyh9f0ad1d_0
  - asciitree=0.3.3=py_2
  - asttokens=2.2.1=pyhd8ed1ab_0
  - attrs=23.1.0=pyh71513ae_1
  - aws-c-auth=0.7.0=h04ea561_0
  - aws-c-cal=0.6.0=h6ba3258_0
  - aws-c-common=0.8.23=hcfcfb64_0
  - aws-c-compression=0.2.17=h420beca_1
  - aws-c-event-stream=0.3.1=h32a1ef9_0
  - aws-c-http=0.7.10=he907102_2
  - aws-c-io=0.13.27=ha35c040_0
  - aws-c-mqtt=0.8.13=hd8b9713_5
  - aws-c-s3=0.3.12=he99ab17_2
  - aws-c-sdkutils=0.1.11=h420beca_1
  - aws-checksums=0.1.16=h420beca_1
  - aws-crt-cpp=0.20.2=h152936e_18
  - aws-sdk-cpp=1.10.57=h90d02da_16
  - babel=2.12.1=pyhd8ed1ab_1
  - backcall=0.2.0=pyh9f0ad1d_0
  - backports=1.0=pyhd8ed1ab_3
  - backports.functools_lru_cache=1.6.5=pyhd8ed1ab_0
  - blosc=1.21.4=hdccc3a2_0
  - bokeh=3.2.0=pyhd8ed1ab_0
  - brotli-python=1.0.9=py39h99910a6_9
  - bzip2=1.0.8=h8ffe710_4
  - c-ares=1.19.1=hcfcfb64_0
  - c-blosc2=2.10.0=h183a6f4_0
  - ca-certificates=2023.5.7=h56e8100_0
  - cachey=0.2.1=pyh9f0ad1d_0
  - certifi=2023.5.7=pyhd8ed1ab_0
  - cfitsio=4.2.0=h9ebe7e4_0
  - charls=2.4.2=h1537add_0
  - charset-normalizer=3.1.0=pyhd8ed1ab_0
  - click=8.1.3=win_pyhd8ed1ab_2
  - cloudpickle=2.2.1=pyhd8ed1ab_0
  - colorama=0.4.6=pyhd8ed1ab_0
  - comm=0.1.3=pyhd8ed1ab_0
  - contourpy=1.1.0=py39h1f6ef14_0
  - cytoolz=0.12.0=py39ha55989b_1
  - czifile=2019.7.2=pyh9f0ad1d_0
  - dask=2023.6.1=pyhd8ed1ab_0
  - dask-core=2023.6.1=pyhd8ed1ab_0
  - dav1d=1.2.1=hcfcfb64_0
  - debugpy=1.6.7=py39h99910a6_0
  - decorator=5.1.1=pyhd8ed1ab_0
  - distributed=2023.6.1=pyhd8ed1ab_0
  - docstring_parser=0.15=pyhd8ed1ab_0
  - docutils=0.16=py39hcbf5309_3
  - entrypoints=0.4=pyhd8ed1ab_0
  - executing=1.2.0=pyhd8ed1ab_0
  - fasteners=0.17.3=pyhd8ed1ab_0
  - freetype=2.12.1=h546665d_1
  - freetype-py=2.4.0=pyhd8ed1ab_0
  - fsspec=2023.6.0=pyh1a96a4e_0
  - gettext=0.21.1=h5728263_0
  - giflib=5.2.1=h64bf75a_3
  - glib=2.76.3=h12be248_0
  - glib-tools=2.76.3=h12be248_0
  - gst-plugins-base=1.22.4=h001b923_1
  - gstreamer=1.22.4=hb4038d2_1
  - heapdict=1.0.1=py_0
  - hsluv=5.0.2=pyh44b312d_0
  - icu=72.1=h63175ca_0
  - idna=3.4=pyhd8ed1ab_0
  - imagecodecs=2023.1.23=py39hd475b99_2
  - imagecodecs-lite=2019.12.3=py39hc266a54_6
  - imageio=2.31.1=pyh24c5eb1_0
  - imagesize=1.4.1=pyhd8ed1ab_0
  - importlib-metadata=6.7.0=pyha770c72_0
  - importlib_metadata=6.7.0=hd8ed1ab_0
  - importlib_resources=5.12.0=pyhd8ed1ab_0
  - in-n-out=0.1.8=pyhd8ed1ab_0
  - intel-openmp=2023.1.0=h57928b3_46319
  - ipykernel=6.24.0=pyh6817e22_0
  - ipython=8.14.0=pyh08f2357_0
  - ipython_genutils=0.2.0=py_1
  - jedi=0.18.2=pyhd8ed1ab_0
  - jinja2=3.1.2=pyhd8ed1ab_1
  - jsonschema=4.17.3=pyhd8ed1ab_0
  - jupyter_client=8.3.0=pyhd8ed1ab_0
  - jupyter_core=5.3.1=py39hcbf5309_0
  - jxrlib=1.1=h8ffe710_2
  - khronos-opencl-icd-loader=2023.04.17=h64bf75a_0
  - kiwisolver=1.4.4=py39h1f6ef14_1
  - krb5=1.20.1=heb0366b_0
  - lazy_loader=0.2=pyhd8ed1ab_0
  - lcms2=2.15=h3e3b177_1
  - lerc=4.0.0=h63175ca_0
  - libabseil=20230125.3=cxx17_h63175ca_0
  - libaec=1.0.6=h63175ca_1
  - libarrow=12.0.1=hbf49b3f_2_cpu
  - libavif=0.11.1=ha7b97ba_2
  - libblas=3.9.0=17_win64_mkl
  - libbrotlicommon=1.0.9=hcfcfb64_9
  - libbrotlidec=1.0.9=hcfcfb64_9
  - libbrotlienc=1.0.9=hcfcfb64_9
  - libcblas=3.9.0=17_win64_mkl
  - libclang=16.0.6=default_heb8d277_0
  - libclang13=16.0.6=default_hc80b9e7_0
  - libcrc32c=1.1.2=h0e60522_0
  - libcurl=8.1.2=h68f0423_0
  - libdeflate=1.18=hcfcfb64_0
  - libevent=2.1.12=h3671451_1
  - libffi=3.4.2=h8ffe710_5
  - libglib=2.76.3=he8f3873_0
  - libgoogle-cloud=2.12.0=hbc1b25b_1
  - libgrpc=1.56.0=hea2d5f7_2
  - libhwloc=2.9.1=nocuda_h15da153_6
  - libiconv=1.17=h8ffe710_0
  - libjpeg-turbo=2.1.5.1=hcfcfb64_0
  - liblapack=3.9.0=17_win64_mkl
  - libogg=1.3.4=h8ffe710_1
  - libpng=1.6.39=h19919ed_0
  - libprotobuf=4.23.3=h1975477_0
  - libsodium=1.0.18=h8d14728_1
  - libsqlite=3.42.0=hcfcfb64_0
  - libssh2=1.11.0=h7dfc565_0
  - libthrift=0.18.1=h06f6336_2
  - libtiff=4.5.1=h6c8260b_0
  - libutf8proc=2.8.0=h82a8f57_0
  - libvorbis=1.3.7=h0e60522_0
  - libwebp-base=1.3.1=hcfcfb64_0
  - libxcb=1.15=hcd874cb_0
  - libxml2=2.11.4=hc3477c8_0
  - libzlib=1.2.13=hcfcfb64_5
  - libzopfli=1.0.3=h0e60522_0
  - locket=1.0.0=pyhd8ed1ab_0
  - lz4=4.3.2=py39hf617134_0
  - lz4-c=1.9.4=hcfcfb64_0
  - m2w64-gcc-libgfortran=5.3.0=6
  - m2w64-gcc-libs=5.3.0=7
  - m2w64-gcc-libs-core=5.3.0=7
  - m2w64-gmp=6.1.0=2
  - m2w64-libwinpthread-git=5.0.0.4634.697f757=2
  - magicgui=0.7.2=pyhd8ed1ab_0
  - mako=1.2.4=pyhd8ed1ab_0
  - markdown-it-py=3.0.0=pyhd8ed1ab_0
  - markupsafe=2.1.3=py39ha55989b_0
  - matplotlib-inline=0.1.6=pyhd8ed1ab_0
  - mdurl=0.1.0=pyhd8ed1ab_0
  - mkl=2022.1.0=h6a75c08_874
  - msgpack-python=1.0.5=py39h1f6ef14_0
  - msys2-conda-epoch=20160418=1
  - mypy_extensions=1.0.0=pyha770c72_0
  - napari-console=0.0.8=pyhd8ed1ab_0
  - napari-czifile2=0.2.7=pyhd8ed1ab_0
  - napari-plugin-engine=0.2.0=pyhd8ed1ab_2
  - napari-svg=0.1.10=pyhd8ed1ab_0
  - nest-asyncio=1.5.6=pyhd8ed1ab_0
  - networkx=3.1=pyhd8ed1ab_0
  - npe2=0.7.0=pyhd8ed1ab_0
  - numcodecs=0.11.0=py39h99910a6_1
  - numpydoc=1.5.0=pyhd8ed1ab_0
  - openjpeg=2.5.0=ha2aaf27_2
  - openssl=3.1.1=hcfcfb64_1
  - orc=1.9.0=hf2b8f0d_1
  - packaging=23.1=pyhd8ed1ab_0
  - pandas=2.0.3=py39h1679cfb_0
  - parso=0.8.3=pyhd8ed1ab_0
  - partd=1.4.0=pyhd8ed1ab_0
  - pcre2=10.40=h17e33f8_0
  - pickleshare=0.7.5=py_1003
  - pillow=10.0.0=py39ha9166d5_0
  - pint=0.22=pyhd8ed1ab_1
  - pip=23.1.2=py39haa95532_0
  - pkgutil-resolve-name=1.3.10=pyhd8ed1ab_0
  - platformdirs=3.8.0=pyhd8ed1ab_0
  - ply=3.11=py_1
  - pooch=1.7.0=pyha770c72_3
  - prompt-toolkit=3.0.39=pyha770c72_0
  - prompt_toolkit=3.0.39=hd8ed1ab_0
  - psutil=5.9.5=py39ha55989b_0
  - psygnal=0.9.0=pyhd8ed1ab_0
  - pthread-stubs=0.4=hcd874cb_1001
  - pthreads-win32=2.9.1=hfa6e2cd_3
  - pure_eval=0.2.2=pyhd8ed1ab_0
  - pyarrow=12.0.1=py39hca4e8af_2_cpu
  - pydantic=1.10.10=py39ha55989b_0
  - pygments=2.15.1=pyhd8ed1ab_0
  - pyopencl=2023.1.1=py39h2ca6765_0
  - pyopengl=3.1.6=pyhd8ed1ab_1
  - pyproject_hooks=1.0.0=pyhd8ed1ab_0
  - pyqt=5.15.7=py39hb77abff_3
  - pyqt5-sip=12.11.0=py39h99910a6_3
  - pyrsistent=0.19.3=py39ha55989b_0
  - pysocks=1.7.1=pyh0701188_6
  - python=3.9.17=h1aa4202_0
  - python-build=0.10.0=pyhd8ed1ab_1
  - python-dateutil=2.8.2=pyhd8ed1ab_0
  - python-tzdata=2023.3=pyhd8ed1ab_0
  - python_abi=3.9=2_cp39
  - pytomlpp=1.0.13=py39h1f6ef14_0
  - pytools=2023.1=pyhd8ed1ab_0
  - pytz=2023.3=pyhd8ed1ab_0
  - pywavelets=1.4.1=py39hc266a54_0
  - pywin32=304=py39h99910a6_2
  - pyyaml=6.0=py39ha55989b_5
  - pyzmq=25.1.0=py39hea35a22_0
  - qt-main=5.15.8=h2c8576c_12
  - qtconsole-base=5.4.3=pyha770c72_0
  - qtpy=2.3.1=pyhd8ed1ab_0
  - re2=2023.03.02=hd4eee63_0
  - requests=2.31.0=pyhd8ed1ab_0
  - rich=13.4.2=pyhd8ed1ab_0
  - scipy=1.9.1=py39h316f440_0
  - setuptools=67.8.0=py39haa95532_0
  - shellingham=1.5.1=pyhd8ed1ab_0
  - sip=6.7.9=py39h99910a6_0
  - six=1.16.0=pyh6c4a22f_0
  - snappy=1.1.10=hfb803bf_0
  - snowballstemmer=2.2.0=pyhd8ed1ab_0
  - sortedcontainers=2.4.0=pyhd8ed1ab_0
  - sphinx=4.5.0=pyh6c4a22f_0
  - sphinxcontrib-applehelp=1.0.4=pyhd8ed1ab_0
  - sphinxcontrib-devhelp=1.0.2=py_0
  - sphinxcontrib-htmlhelp=2.0.1=pyhd8ed1ab_0
  - sphinxcontrib-jsmath=1.0.1=py_0
  - sphinxcontrib-qthelp=1.0.3=py_0
  - sphinxcontrib-serializinghtml=1.1.5=pyhd8ed1ab_2
  - sqlite=3.41.2=h2bbff1b_0
  - stack_data=0.6.2=pyhd8ed1ab_0
  - superqt=0.4.1=pyhd8ed1ab_0
  - tbb=2021.9.0=h91493d7_0
  - tblib=1.7.0=pyhd8ed1ab_0
  - tifffile=2023.7.4=pyhd8ed1ab_0
  - tk=8.6.12=h8ffe710_0
  - toml=0.10.2=pyhd8ed1ab_0
  - tomli=2.0.1=pyhd8ed1ab_0
  - toolz=0.12.0=pyhd8ed1ab_0
  - tornado=6.3.2=py39ha55989b_0
  - tqdm=4.65.0=pyhd8ed1ab_1
  - traitlets=5.9.0=pyhd8ed1ab_0
  - typer=0.9.0=pyhd8ed1ab_0
  - typing-extensions=4.7.1=hd8ed1ab_0
  - typing_extensions=4.7.1=pyha770c72_0
  - tzdata=2023c=h04d1e81_0
  - ucrt=10.0.22621.0=h57928b3_0
  - urllib3=2.0.3=pyhd8ed1ab_1
  - vc=14.2=h21ff451_1
  - vc14_runtime=14.36.32532=hfdfe4a8_17
  - vs2015_runtime=14.36.32532=h05e6639_17
  - wcwidth=0.2.6=pyhd8ed1ab_0
  - wheel=0.38.4=py39haa95532_0
  - win_inet_pton=1.1.0=pyhd8ed1ab_6
  - wrapt=1.15.0=py39ha55989b_0
  - xorg-libxau=1.0.11=hcd874cb_0
  - xorg-libxdmcp=1.1.3=hcd874cb_0
  - xyzservices=2023.5.0=pyhd8ed1ab_1
  - xz=5.2.6=h8d14728_0
  - yaml=0.2.5=h8ffe710_2
  - zarr=2.15.0=pyhd8ed1ab_0
  - zeromq=4.3.4=h0e60522_1
  - zfp=1.0.0=h63175ca_3
  - zict=3.0.0=pyhd8ed1ab_0
  - zipp=3.15.0=pyhd8ed1ab_0
  - zlib-ng=2.0.7=hcfcfb64_0
  - zstd=1.5.2=h12be248_6
  - pip:
      - apoc==0.12.0
      - autopep8==2.0.2
      - cycler==0.11.0
      - fonttools==4.40.0
      - joblib==1.3.1
      - matplotlib==3.7.2
      - napari==0.4.17
      - napari-accelerated-pixel-and-object-classification==0.12.3
      - napari-time-slicer==0.4.9
      - napari-tools-menu==0.1.19
      - napari-workflows==0.2.9
      - numpy==1.24.4
      - pyclesperanto-prototype==0.24.1
      - pycodestyle==2.10.0
      - pyparsing==3.0.9
      - scikit-image==0.21.0
      - scikit-learn==1.3.0
      - threadpoolctl==3.1.0
      - transforms3d==0.4.1
      - vispy==0.11.0
haesleinhuepf commented 1 year ago

Hi @milenovic ,

can you tell the dimensions and pixel size of the image and the annotation? E g. use the menu Tools > Utilities > Layer Details for that.

Thanks!

Best, Robert

milenovic commented 1 year ago

Thanks for the reply @haesleinhuepf, I don't see the Layer Details under tools: image Am I missing something?

But here is the original image.zip It is 2396 x 2396 pixels, 16 bit. The import is enabled by napari-czifile2.

Best, Milan

milenovic commented 1 year ago

Ah, I see I was missing a plugin for layer details. Here is the output: layerdetails

milenovic commented 1 year ago

looking deeper I tried to convert my .czi image to .tif in imageJ first and then import to napari. This way it worked! So there is some issue with using .czi Here are layer details with .tif image: layerdetailstiff

haesleinhuepf commented 1 year ago

Thanks for debuggin the issue @milenovic !

I tried to convert my .czi image to .tif in imageJ first and then import to napari. This way it worked!

Awesome. It's a bit complicated though. That's why I implemented another way for doing this. The data has shape (1,1, height, width) and the function np.squeeze can convert it to data of shape (height, width). This should work nicely with APOC then. As convenience function I added squeeze to napari-segment-blobs-and-things-with-membranes. After installing it you find the menu Tools > Transforms > Remove axes of length 1 (numpy.squeeze, nsbatwm). Give it a try and let me know if it works!

pip install napari-segment-blobs-and-things-with-membranes==0.3.6
milenovic commented 1 year ago

Thanks, that is convenient and it works!

haesleinhuepf commented 1 year ago

Awesome, thanks for the feedback!