Example #1
0
    def test_channel(self, small_cont: ImageContainer, channel: int):
        segment(small_cont, copy=False, layer="image", channel=channel)

        assert Key.img.segment("watershed") in small_cont
        np.testing.assert_array_equal(
            list(small_cont[Key.img.segment("watershed")].dims),
            ["y", "x", f"{small_cont['image'].dims[-1]}:{channel}"])
Example #2
0
    def test_parallelize(self, small_cont: ImageContainer):
        res1 = segment(small_cont, layer="image", n_jobs=1, copy=True)
        res2 = segment(small_cont, layer="image", n_jobs=2, copy=True)

        np.testing.assert_array_equal(
            res1[Key.img.segment("watershed")].values,
            res2[Key.img.segment("watershed")].values)
Example #3
0
    def test_copy(self, small_cont: ImageContainer):
        prev_keys = set(small_cont)
        res = segment(small_cont, copy=True, layer="image")

        assert isinstance(res, ImageContainer)
        assert set(small_cont) == prev_keys
        assert Key.img.segment("watershed") in res
Example #4
0
    def test_size(self, small_cont: ImageContainer,
                  dy: Optional[Union[int, float]], dx: Optional[Union[int,
                                                                      float]]):
        res = segment(small_cont, size=(dy, dx), copy=True)

        assert isinstance(res, ImageContainer)
        assert res.shape == small_cont.shape
Example #5
0
    def test_watershed_works(self, size: Optional[int]):
        img_orig = np.zeros((100, 200, 30), dtype=np.float64)
        img_orig[2:10, 2:10] = 1.0
        img_orig[30:34, 10:16] = 1.0

        cont = ImageContainer(img_orig, layer="image_0")
        segment(
            img=cont,
            method="watershed",
            layer="image_0",
            layer_added="segment",
            size=size,
            channel=0,
            thresh=0.5,
        )
        # check that blobs are in segments
        assert np.mean(
            cont.data["segment"].values[img_orig[:, :, 0] > 0] > 0) > 0.5
Example #6
0
    def test_key_added(self, small_cont: ImageContainer,
                       key_added: Optional[str]):
        res = segment(small_cont,
                      copy=False,
                      layer="image",
                      layer_added=key_added)

        assert res is None
        assert Key.img.segment("watershed",
                               layer_added=key_added) in small_cont
Example #7
0
    def test_method(self, small_cont: ImageContainer, method: Union[str,
                                                                    Callable]):
        res = segment(small_cont, method=method, copy=True)

        assert isinstance(res, ImageContainer)
        assert res.shape == small_cont.shape

        if callable(method):
            method = SegmentationBackend.CUSTOM.s

        assert Key.img.segment(method) in res

        if method in ("log", "dog", "dog"):
            assert res[Key.img.segment(method)].values.max() <= 1
Example #8
0
 def test_invalid_layer(self, small_cont: ImageContainer):
     with pytest.raises(KeyError,
                        match=r"Image layer `foobar` not found in"):
         segment(small_cont, layer="foobar")