def test_segmentation_centroid(self, small_cont_seg: ImageContainer): features = small_cont_seg.features_segmentation( label_layer="segmented", intensity_layer=None, feature_name="foo", props=["centroid"] ) assert isinstance(features, dict) assert "foo_centroid" in features assert isinstance(features["foo_centroid"], np.ndarray) assert features["foo_centroid"].ndim == 2
def test_segmentation_props(self, small_cont_seg: ImageContainer, props: Sequence[str]): if not len(props): with pytest.raises(ValueError, match=r"No properties have been selected."): small_cont_seg.features_segmentation( label_layer="segmented", intensity_layer="image", feature_name="foo", props=props ) else: features = small_cont_seg.features_segmentation( label_layer="segmented", intensity_layer="image", feature_name="foo", props=props, channels=[0] ) haystack = features.keys() int_props = [p for p in props if "intensity" in props] no_int_props = [p for p in props if "intensity" not in props] for p in no_int_props: assert any(f"{p}_mean" in h for h in haystack), haystack assert any(f"{p}_std" in h for h in haystack), haystack for p in int_props: assert any(f"ch-0_{p}_mean" in h for h in haystack), haystack assert any(f"ch-0_{p}_std" in h for h in haystack), haystack
def test_segmentation_label(self, small_cont_seg: ImageContainer): features = small_cont_seg.features_segmentation("image", feature_name="foo", props=["label"]) assert isinstance(features, dict) assert "foo_label" in features assert features["foo_label"] == 254
def test_segmentation_invalid_props(self, small_cont: ImageContainer): with pytest.raises(ValueError, match=r"Invalid property `foobar`. Valid properties are"): small_cont.features_segmentation("image", feature_name="foo", props=["foobar"])