Beispiel #1
0
    def add_roi_layer(self, image_info: ImageInfo):
        if image_info.roi_info.roi is None:
            return
        try:
            max_num = max(1, image_info.roi_count)
        except ValueError:
            max_num = 1
        roi = image_info.roi_info.alternative.get(
            self.image_state.roi_presented, image_info.roi_info.roi)
        if self.image_state.only_borders:

            data = calculate_borders(
                roi.transpose(ORDER_DICT[self._current_order]),
                self.image_state.borders_thick // 2,
                self.viewer.dims.ndisplay == 2,
            ).transpose(np.argsort(ORDER_DICT[self._current_order]))
            image_info.roi = self.viewer.add_image(
                data,
                scale=image_info.image.normalized_scaling(),
                contrast_limits=[0, max_num],
            )
        else:
            image_info.roi = self.viewer.add_image(
                roi,
                scale=image_info.image.normalized_scaling(),
                contrast_limits=[0, max_num],
                name="ROI",
                blending="translucent",
            )
        image_info.roi._interpolation[3] = Interpolation3D.NEAREST
 def add_segmentation_layer(self, image_info: ImageInfo):
     if image_info.segmentation_info.segmentation is None:
         return
     try:
         max_num = max(1, image_info.segmentation_count)
     except ValueError:
         max_num = 1
     if self.image_state.only_borders:
         data = calculate_borders(
             image_info.segmentation_info.segmentation,
             self.image_state.borders_thick // 2,
             self.viewer.dims.ndisplay == 2,
         )
         image_info.segmentation = self.viewer.add_image(
             data,
             scale=image_info.image.normalized_scaling(),
             contrast_limits=[0, max_num],
         )
     else:
         image_info.segmentation = self.viewer.add_image(
             image_info.segmentation_info.segmentation,
             scale=image_info.image.normalized_scaling(),
             contrast_limits=[0, max_num],
             name="segmentation",
             blending="translucent",
         )
     image_info.segmentation._interpolation[3] = Interpolation3D.NEAREST
Beispiel #3
0
 def test_sizes_3d(self, dtype):
     data = np.zeros((1, 10, 20, 30), dtype=dtype)
     data[0, 2:-2, 2:-2, 2:-2] = 1
     res = calculate_borders(data, 0, False)
     data[0, 3:-3, 3:-3, 3:-3] = 0
     assert np.all(res == data)
     assert res.dtype == dtype
Beispiel #4
0
 def test_simple_2d(self, dtype):
     data = np.zeros((1, 10, 10, 10), dtype=dtype)
     data[0, 2:-2, 2:-2, 2:-2] = 1
     res = calculate_borders(data, 0, True)
     data[:, :, 3:-3, 3:-3] = 0
     assert np.all(res == data)
     assert res.dtype == dtype
Beispiel #5
0
 def test_labels_3d(self, num, dtype):
     data = np.zeros((1, 10, num * 10, 10), dtype=dtype)
     for ind in range(num):
         data[0, 2:-2, ind * 10 + 2:ind * 10 + 8, 2:-2] = ind + 1
     res = calculate_borders(data, 0, False)
     for ind in range(num):
         data[0, 3:-3, ind * 10 + 3:ind * 10 + 7, 3:-3] = 0
     assert np.all(res == data)
     assert res.dtype == dtype
Beispiel #6
0
 def test_simple_thick_2d(self, dtype):
     data = np.zeros((1, 10, 10, 10), dtype=dtype)
     data[0, 2:-2, 2:-2, 2:-2] = 1
     res = calculate_borders(data, 1, True)
     data2 = np.copy(data)
     res2 = np.copy(res)
     res2[data == 0] = 0
     data2[0, :, 4:-4, 4:-4] = 0
     assert np.all(res2 == data2)
     assert res.dtype == dtype
     data[0, 2:-2, 1, 2:-2] = 1
     data[0, 2:-2, -2, 2:-2] = 1
     data[0, 2:-2, 2:-2, 1] = 1
     data[0, 2:-2, 2:-2, -2] = 1
     data[0, :, 4:-4, 4:-4] = 0
     assert np.all(res == data)