Esempio n. 1
0
 def test_simple_mask(self):
     mask_array = np.zeros((10, 20, 20), dtype=np.uint8)
     mask_array[3:7, 6:14, 6:14] = 1
     prop = MaskProperty(
         dilate=RadiusType.NO,
         dilate_radius=0,
         fill_holes=RadiusType.NO,
         max_holes_size=0,
         save_components=False,
         clip_to_mask=False,
     )
     new_mask = calculate_mask(prop, mask_array, None, (1, 1, 1))
     assert np.all(new_mask == mask_array)
     mask_array2 = np.copy(mask_array)
     mask_array2[4:6, 8:12, 8:12] = 2
     new_mask = calculate_mask(prop, mask_array2, None, (1, 1, 1))
     assert np.all(new_mask == mask_array)
     prop2 = MaskProperty(
         dilate=RadiusType.NO,
         dilate_radius=0,
         fill_holes=RadiusType.NO,
         max_holes_size=0,
         save_components=True,
         clip_to_mask=False,
     )
     new_mask = calculate_mask(prop2, mask_array2, None, (1, 1, 1))
     assert np.all(new_mask == mask_array2)
Esempio n. 2
0
 def test_reversed_mask(self):
     mask_base_array = np.zeros((30, 30, 30), dtype=np.uint8)
     mask_base_array[10:20, 10:20, 10:20] = 1
     mask2_array = np.copy(mask_base_array)
     mask2_array[13:17, 13:17, 13:17] = 0
     prop1 = MaskProperty(
         dilate=RadiusType.NO,
         dilate_radius=-0,
         fill_holes=RadiusType.NO,
         max_holes_size=0,
         save_components=False,
         clip_to_mask=False,
         reversed_mask=False,
     )
     prop2 = MaskProperty(
         dilate=RadiusType.NO,
         dilate_radius=-0,
         fill_holes=RadiusType.NO,
         max_holes_size=0,
         save_components=False,
         clip_to_mask=False,
         reversed_mask=True,
     )
     new_mask1 = calculate_mask(prop1, mask_base_array, mask2_array,
                                (1, 1, 1))
     new_mask2 = calculate_mask(prop2, mask_base_array, mask2_array,
                                (1, 1, 1))
     assert np.all(new_mask1 == mask_base_array)
     assert np.all(new_mask2 == (mask_base_array == 0))
Esempio n. 3
0
    def test_fill_holes(self):
        mask_base_array = np.zeros((1, 20, 30, 30), dtype=np.uint8)
        mask_base_array[:, 4:16, 8:22, 8:22] = 1
        mask1_array = np.copy(mask_base_array)
        mask1_array[:, 4:16, 10:15, 10:15] = 0
        prop = MaskProperty(
            dilate=RadiusType.NO,
            dilate_radius=0,
            fill_holes=RadiusType.R2D,
            max_holes_size=0,
            save_components=False,
            clip_to_mask=False,
        )
        new_mask = calculate_mask(prop, mask1_array, None, (1, 1, 1))
        assert np.all(mask_base_array == new_mask)

        prop = MaskProperty(
            dilate=RadiusType.NO,
            dilate_radius=0,
            fill_holes=RadiusType.R3D,
            max_holes_size=0,
            save_components=False,
            clip_to_mask=False,
        )
        new_mask = calculate_mask(prop, mask1_array, None, (1, 1, 1))
        assert np.all(mask1_array == new_mask)

        mask2_array = np.copy(mask1_array)
        mask2_array[:, 5:15, 10:15, 17:20] = 0
        new_mask = calculate_mask(prop, mask2_array, None, (1, 1, 1))
        assert np.all(mask1_array == new_mask)
Esempio n. 4
0
    def test_fill_holes_components(self):
        mask_base_array = np.zeros((20, 30, 30), dtype=np.uint8)
        mask_base_array[4:16, 6:15, 6:24] = 1
        mask_base_array[4:16, 15:24, 6:24] = 2
        res_mask1 = (mask_base_array > 0).astype(np.uint8)
        res_mask2 = np.copy(mask_base_array)
        mask_base_array[6:14, 8:12, 8:22] = 0
        mask_base_array[6:14, 18:22, 8:22] = 0
        prop1 = MaskProperty(
            dilate=RadiusType.NO,
            dilate_radius=0,
            fill_holes=RadiusType.R3D,
            max_holes_size=0,
            save_components=False,
            clip_to_mask=False,
        )
        prop2 = MaskProperty(
            dilate=RadiusType.NO,
            dilate_radius=0,
            fill_holes=RadiusType.R3D,
            max_holes_size=0,
            save_components=True,
            clip_to_mask=False,
        )
        new_mask = calculate_mask(prop1, mask_base_array, None, (1, 1, 1))
        assert np.all(new_mask == res_mask1)
        new_mask = calculate_mask(prop2, mask_base_array, None, (1, 1, 1))
        assert np.all(new_mask == res_mask2)

        mask_base_array[6:14, 14:16, 8:22] = 0
        res_mask2[6:14, 14:16, 8:22] = 0
        new_mask = calculate_mask(prop1, mask_base_array, None, (1, 1, 1))
        assert np.all(new_mask == res_mask1)
        new_mask = calculate_mask(prop2, mask_base_array, None, (1, 1, 1))
        assert np.all(new_mask == res_mask2)
Esempio n. 5
0
    def test_fill_holes_size(self):
        mask_base_array = np.zeros((1, 20, 20, 40), dtype=np.uint8)
        mask_base_array[0, 2:18, 2:18, 4:36] = 1
        mask_base_array[0, 4:16, 4:16, 6:18] = 0
        mask1_array = np.copy(mask_base_array)
        mask1_array[0, 6:14, 6:14, 24:32] = 0

        prop1 = MaskProperty(
            dilate=RadiusType.NO,
            dilate_radius=0,
            fill_holes=RadiusType.R2D,
            max_holes_size=70,
            save_components=False,
            clip_to_mask=False,
        )
        prop2 = MaskProperty(
            dilate=RadiusType.NO,
            dilate_radius=0,
            fill_holes=RadiusType.R3D,
            max_holes_size=530,
            save_components=True,
            clip_to_mask=False,
        )

        new_mask = calculate_mask(prop1, mask_base_array, None, (1, 1, 1))
        assert np.all(new_mask == mask_base_array)
        new_mask = calculate_mask(prop2, mask_base_array, None, (1, 1, 1))
        assert np.all(new_mask == mask_base_array)
Esempio n. 6
0
 def test_compare(self):
     ob1 = MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, False, True)
     ob2 = MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, False, True,
                        False)
     ob3 = MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, False, True,
                        True)
     assert ob1 == ob2
     assert ob1 != ob3
     assert ob2 != ob3
Esempio n. 7
0
 def test_single(self):
     mask = np.zeros((10, 10, 10), dtype=np.uint8)
     mask[2:8, 2:8, 2:8] = 1
     mask2 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, False, True),
         mask, None, (1, 1, 1))
     assert np.all(mask2 == mask)
     mask3 = np.copy(mask)
     mask3[mask > 0] = 2
     mask2 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, False, True),
         mask, None, (1, 1, 1))
     assert np.all(mask2 == mask)
Esempio n. 8
0
 def test_dilate(self):
     mask = np.zeros((1, 10, 10, 10), dtype=np.uint8)
     mask[0, 2:8, 2:8, 2:8] = 1
     mask2 = calculate_mask(
         MaskProperty(RadiusType.R3D, -1, RadiusType.NO, -1, False, True),
         mask, None, (1, 1, 1))
     mask3 = np.zeros((1, 10, 10, 10), dtype=np.uint8)
     mask3[0, 3:7, 3:7, 3:7] = 1
     assert np.all(mask2 == mask3)
     mask2 = calculate_mask(
         MaskProperty(RadiusType.R2D, -1, RadiusType.NO, -1, False, True),
         mask, None, (1, 1, 1))
     mask3 = np.zeros((1, 10, 10, 10), dtype=np.uint8)
     mask3[0, 2:8, 3:7, 3:7] = 1
     assert np.all(mask2 == mask3)
Esempio n. 9
0
 def test_mask_property_combinations(self, dilate, radius, fill_holes,
                                     max_holes_size, save_components,
                                     clip_to_mask, reversed_mask, old_mask):
     mask = np.zeros((1, 6, 6, 15), dtype=np.uint8)
     im = Image(data=mask.copy(),
                image_spacing=(3, 1, 1),
                file_path="",
                axes_order="TZYX")
     mask[:, 1:-1, 1:-1, 2:5] = 1
     mask[:, 2:-2, 2:-2, 3:4] = 0
     mask[:, 1:-1, 1:-1, 6:9] = 2
     mask[:, 2:-2, 2:-2, 7:8] = 0
     mask[:, 1:-1, 1:-1, 10:13] = 3
     mask[:, 2:-2, 2:-2, 11:12] = 0
     mask = im.fit_mask_to_image(mask)
     assert np.all(np.unique(mask.flat) == [0, 1, 2, 3])
     _old_mask = np.zeros(mask.shape,
                          dtype=mask.dtype) if old_mask else None
     mp = MaskProperty(
         dilate=dilate,
         dilate_radius=radius,
         fill_holes=fill_holes,
         max_holes_size=max_holes_size,
         save_components=save_components,
         clip_to_mask=clip_to_mask,
         reversed_mask=reversed_mask,
     )
     mask1 = calculate_mask(mp,
                            mask,
                            _old_mask,
                            im.spacing,
                            time_axis=im.time_pos)
     assert mask1.shape == mask.shape
Esempio n. 10
0
 def test_save_component_fill_holes_problematic(self):
     mask = np.zeros((12, 12, 12), dtype=np.uint8)
     mask[2:7, 2:-2, 2:-2] = 3
     mask[7:-2, 2:-2, 2:-2] = 2
     mask[4:-4, 4:-4, 4:-4] = 1
     mask2 = np.copy(mask)
     mask2[5, 5, 5] = 0
     mask2[3, 3, 3] = 0
     mask1 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.R2D, -1, True, True),
         mask2, None, (1, 1, 1))
     assert np.all(mask == mask1)
     mask1 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.R3D, -1, True, True),
         mask2, None, (1, 1, 1))
     assert np.all(mask == mask1)
    def test_pipeline_simple(self):
        image = self.get_image()
        prop1 = MaskProperty(
            dilate=RadiusType.NO,
            dilate_radius=-0,
            fill_holes=RadiusType.NO,
            max_holes_size=0,
            save_components=False,
            clip_to_mask=False,
        )
        parameters1 = {
            "channel": 0,
            "minimum_size": 30,
            "threshold": {
                "name": "Manual",
                "values": {
                    "threshold": 5
                }
            },
            "noise_filtering": {
                "name": "None",
                "values": {}
            },
            "side_connection": False,
        }
        parameters2 = {
            "channel": 1,
            "minimum_size": 30,
            "threshold": {
                "name": "Manual",
                "values": {
                    "threshold": 5
                }
            },
            "noise_filtering": {
                "name": "None",
                "values": {}
            },
            "side_connection": False,
        }
        seg_profile1 = SegmentationProfile(name="Unknown",
                                           algorithm="Lower threshold",
                                           values=parameters1)
        pipeline_element = SegmentationPipelineElement(
            mask_property=prop1, segmentation=seg_profile1)
        seg_profile2 = SegmentationProfile(name="Unknown",
                                           algorithm="Lower threshold",
                                           values=parameters2)

        pipeline = SegmentationPipeline(name="test",
                                        segmentation=seg_profile2,
                                        mask_history=[pipeline_element])
        result = calculate_pipeline(image=image,
                                    mask=None,
                                    pipeline=pipeline,
                                    report_fun=empty)
        result_segmentation = np.zeros((50, 100, 100), dtype=np.uint8)
        result_segmentation[10:40, 20:80, 40:60] = 1
        assert np.all(result.segmentation == result_segmentation)
Esempio n. 12
0
    def test_dilate_spacing_positive(self):
        mask_base_array = np.zeros((1, 30, 30, 30), dtype=np.uint8)
        mask_base_array[:, 10:20, 10:20, 10:20] = 1
        prop1 = MaskProperty(
            dilate=RadiusType.R3D,
            dilate_radius=1,
            fill_holes=RadiusType.NO,
            max_holes_size=70,
            save_components=False,
            clip_to_mask=False,
        )
        prop2 = MaskProperty(
            dilate=RadiusType.R3D,
            dilate_radius=2,
            fill_holes=RadiusType.NO,
            max_holes_size=70,
            save_components=False,
            clip_to_mask=False,
        )
        prop3 = MaskProperty(
            dilate=RadiusType.R3D,
            dilate_radius=3,
            fill_holes=RadiusType.NO,
            max_holes_size=70,
            save_components=False,
            clip_to_mask=False,
        )
        res_array1 = np.zeros((30, 30, 30), dtype=np.uint8)
        res_array1[10:20, 9:21, 9:21] = 1
        new_mask = calculate_mask(prop1, mask_base_array, None, (3, 1, 1))
        assert np.all(new_mask[0] == res_array1)
        res_array2 = np.zeros((30, 30, 30), dtype=np.uint8)
        res_array2[10:20, 8:22, 8:22] = 1
        res_array2[(9, 20), 9:21, 9:21] = 1
        res_array2[:, (8, 21, 8, 21), (8, 8, 21, 21)] = 0
        new_mask = calculate_mask(prop2, mask_base_array, None, (3, 1, 1))
        assert np.all(new_mask[0] == res_array2)
        res_array3 = np.zeros((30, 30, 30), dtype=np.uint8)
        res_array3[(9, 20), 8:22, 9:21] = 1
        res_array3[(9, 9, 20, 20), 9:21, (8, 21, 8, 21)] = 1

        res_array3[10:20, 7:23, 9:21] = 1
        res_array3[10:20, 8:22, (8, 21)] = 1
        res_array3[10:20, 9:21, (7, 22)] = 1
        new_mask = calculate_mask(prop3, mask_base_array, None, (3, 1, 1))
        assert np.all(new_mask == res_array3)
Esempio n. 13
0
 def test_str(self):
     text = str(
         MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, False, True))
     assert "dilate radius" not in text
     assert "max holes size" not in text
     text = str(
         MaskProperty(RadiusType.R2D, 0, RadiusType.NO, -1, False, True))
     assert "dilate radius" in text
     assert "max holes size" not in text
     text = str(
         MaskProperty(RadiusType.NO, 0, RadiusType.R2D, -1, False, True))
     assert "dilate radius" not in text
     assert "max holes size" in text
     text = str(
         MaskProperty(RadiusType.R3D, 0, RadiusType.R2D, -1, False, True))
     assert "dilate radius" in text
     assert "max holes size" in text
Esempio n. 14
0
 def test_fil_holes_2d(self):
     mask = np.zeros((10, 10, 10), dtype=np.uint8)
     mask[2:8, 2:8, 2:8] = 1
     mask2 = np.copy(mask)
     mask2[:, 4:6, 4:6] = 0
     mask3 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.R2D, -1, False, True),
         mask2, None, (1, 1, 1))
     assert np.all(mask3 == mask)
     mask3 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.R2D, 3, False, True),
         mask2, None, (1, 1, 1))
     assert np.all(mask3 == mask2)
     mask3 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.R2D, 4, False, True),
         mask2, None, (1, 1, 1))
     assert np.all(mask3 == mask)
Esempio n. 15
0
 def test_fil_holes_3d_torus(self):
     mask = np.zeros((1, 10, 10, 10), dtype=np.uint8)
     mask[0, 2:8, 2:8, 2:8] = 1
     mask[0, :, 4:6, 4:6] = 0
     mask2 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.R3D, -1, False, True),
         mask, None, (1, 1, 1))
     assert np.all(mask2 == mask)
Esempio n. 16
0
 def test_chose_components(self):
     mask = np.zeros((12, 12, 12), dtype=np.uint8)
     mask[2:7, 2:-2, 2:-2] = 3
     mask[7:-2, 2:-2, 2:-2] = 2
     mask[4:-4, 4:-4, 4:-4] = 1
     mask1 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.R2D, -1, True, True),
         mask, None, (1, 1, 1), [1, 3])
     assert np.all(np.unique(mask1) == [0, 1, 3])
Esempio n. 17
0
 def test_reverse(self):
     mask = np.zeros((10, 10, 10), dtype=np.uint8)
     mask[3:7, 3:7, 3:7] = 1
     mask2 = np.ones((10, 10, 10), dtype=np.uint8)
     mask2[mask > 0] = 0
     mask3 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, False, True,
                      True), mask, None, (1, 1, 1))
     assert np.all(mask3 == mask2)
Esempio n. 18
0
 def test_clip(self):
     mask = np.zeros((10, 10, 10), dtype=np.uint8)
     mask[3:7, 3:7, 3:7] = 1
     mask2 = calculate_mask(
         MaskProperty(RadiusType.R3D, 1, RadiusType.NO, -1, False, True),
         mask, mask, (1, 1, 1))
     assert np.all(mask == mask2)
     mask2[:, 4:6, 4:6] = 0
     mask3 = calculate_mask(
         MaskProperty(RadiusType.R3D, 1, RadiusType.NO, -1, False, True),
         mask, mask2, (1, 1, 1))
     assert np.all(mask3 == mask2)
     mask2[:] = 0
     mask2[4:6, 4:6, 4:6] = 1
     mask3 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, False, True,
                      True), mask2, mask, (1, 1, 1))
     mask[mask2 == 1] = 0
     assert np.all(mask3 == mask)
Esempio n. 19
0
 def test_save_components(self):
     mask = np.zeros((10, 10, 10), dtype=np.uint8)
     mask[2:8, 2:8, 2:8] = 1
     mask2 = np.copy(mask)
     mask2[2:8, 4:6, 4:6] = 2
     mask3 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, False, True),
         mask2, None, (1, 1, 1))
     assert np.all(mask3 == mask)
     mask3 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, True, True),
         mask2, None, (1, 1, 1))
     assert np.all(mask3 == mask2)
     mask4 = np.copy(mask2)
     mask4[mask4 == 2] = 3
     mask3 = calculate_mask(
         MaskProperty(RadiusType.NO, 0, RadiusType.NO, -1, True, True),
         mask4, None, (1, 1, 1))
     assert np.all(mask3 == mask4)
Esempio n. 20
0
 def get_mask_property(self):
     return MaskProperty(
         dilate=self.dilate_dim.value() if self.dilate_radius.value() != 0 else RadiusType.NO,
         dilate_radius=self.dilate_radius.value() if self.dilate_dim.value() != RadiusType.NO else 0,
         fill_holes=self.fill_holes.value() if self.max_hole_size.value() != 0 else RadiusType.NO,
         max_holes_size=self.max_hole_size.value() if self.fill_holes.value() != RadiusType.NO else 0,
         save_components=self.save_components.isChecked(),
         clip_to_mask=self.clip_to_mask.isChecked(),
         reversed_mask=self.reversed_check.isChecked(),
     )
Esempio n. 21
0
 def test_time_axis(self, time):
     mask = np.zeros((time, 6, 6, 6), dtype=np.uint8)
     mask[:, 1:-1, 1:-1, 2:5] = 1
     mask[:, 2:-2, 2:-2, 3:4] = 0
     mp = MaskProperty(
         dilate=RadiusType.NO,
         dilate_radius=0,
         fill_holes=RadiusType.NO,
         max_holes_size=-1,
         save_components=False,
         clip_to_mask=False,
     )
     mask1 = calculate_mask(mp, mask, None, (1, 1, 1))
     assert mask1.shape == mask.shape
Esempio n. 22
0
    def test_dilate_spacing_negative(self, radius):
        mask_base_array = np.zeros((1, 30, 30, 30), dtype=np.uint8)
        mask_base_array[:, 10:20, 5:25, 5:25] = 1
        res_array1 = np.zeros((1, 30, 30, 30), dtype=np.uint8)
        s = slice(10, 20) if radius == -1 else slice(11, 19)
        res_array1[:, s, 5 - radius:25 + radius, 5 - radius:25 + radius] = 1

        prop1 = MaskProperty(
            dilate=RadiusType.R3D,
            dilate_radius=radius,
            fill_holes=RadiusType.NO,
            max_holes_size=70,
            save_components=False,
            clip_to_mask=False,
        )
        new_mask = calculate_mask(prop1, mask_base_array, None, (3, 1, 1))
        assert np.all(new_mask == res_array1)
Esempio n. 23
0
 def test_dilate(self, radius_type, radius, time):
     mask_base_array = np.zeros((time, 30, 30, 30), dtype=np.uint8)
     mask_base_array[:, 10:20, 10:20, 10:20] = 1
     prop1 = MaskProperty(
         dilate=radius_type,
         dilate_radius=radius,
         fill_holes=RadiusType.NO,
         max_holes_size=70,
         save_components=False,
         clip_to_mask=False,
     )
     res_array1 = np.zeros((1, 30, 30, 30), dtype=np.uint8)
     slices: List[Union[int, slice]] = [slice(None)] * 4
     for i in range(1, 4):
         slices[i] = slice(10 - radius, 20 + radius)
     if radius_type == RadiusType.R2D:
         slices[1] = slice(10, 20)
     res_array1[tuple(slices)] = 1
     if radius_type == RadiusType.R3D:
         res_array1[:, (9, 9, 9, 9), (9, 9, 20, 20), (9, 20, 20, 9)] = 0
         res_array1[:, (20, 20, 20, 20), (9, 9, 20, 20), (9, 20, 20, 9)] = 0
     new_mask = calculate_mask(prop1, mask_base_array, None, (1, 1, 1))
     assert np.all(new_mask == res_array1)
Esempio n. 24
0
 def test_simple_mask(self):
     assert MaskProperty.simple_mask() == MaskProperty(
         RadiusType.NO, 0, RadiusType.NO, 0, False, False)
Esempio n. 25
0
    def create_calculation_plan3():
        parameters = {
            "channel": 1,
            "minimum_size": 200,
            "threshold": {
                "name": "Base/Core",
                "values": {
                    "core_threshold": {
                        "name": "Manual",
                        "values": {
                            "threshold": 30000
                        }
                    },
                    "base_threshold": {
                        "name": "Manual",
                        "values": {
                            "threshold": 13000
                        }
                    },
                },
            },
            "noise_filtering": {
                "name": "Gauss",
                "values": {
                    "dimension_type": DimensionType.Layer,
                    "radius": 1.0
                }
            },
            "side_connection": False,
            "sprawl_type": {
                "name": "Euclidean",
                "values": {}
            },
        }

        segmentation = ROIExtractionProfile(
            name="test",
            algorithm="Lower threshold with watershed",
            values=parameters)
        mask_suffix = MaskSuffix(name="", suffix="_mask")
        chosen_fields = [
            MeasurementEntry(
                name="Segmentation Volume",
                calculation_tree=Leaf(name="Volume",
                                      area=AreaType.ROI,
                                      per_component=PerComponent.No),
            ),
            MeasurementEntry(
                name="Segmentation Volume/Mask Volume",
                calculation_tree=Node(
                    left=Leaf(name="Volume",
                              area=AreaType.ROI,
                              per_component=PerComponent.No),
                    op="/",
                    right=Leaf(name="Volume",
                               area=AreaType.Mask,
                               per_component=PerComponent.No),
                ),
            ),
            MeasurementEntry(
                "Segmentation Components Number",
                calculation_tree=Leaf("Components number",
                                      area=AreaType.ROI,
                                      per_component=PerComponent.No),
            ),
            MeasurementEntry(
                "Segmentation Volume per component",
                calculation_tree=Leaf("Volume",
                                      area=AreaType.ROI,
                                      per_component=PerComponent.Yes),
            ),
        ]
        statistic = MeasurementProfile(name="base_measure",
                                       chosen_fields=chosen_fields,
                                       name_prefix="")
        statistic_calculate = MeasurementCalculate(
            channel=0,
            units=Units.µm,
            measurement_profile=statistic,
            name_prefix="")
        mask_create = MaskCreate(
            "",
            MaskProperty(RadiusType.NO, 0, RadiusType.NO, 0, True, False,
                         False))
        parameters2 = {
            "channel": 1,
            "minimum_size": 200,
            "threshold": {
                "name": "Manual",
                "values": {
                    "threshold": 30000
                }
            },
            "noise_filtering": {
                "name": "Gauss",
                "values": {
                    "dimension_type": DimensionType.Layer,
                    "radius": 1.0
                }
            },
            "side_connection": False,
        }

        segmentation2 = ROIExtractionProfile(name="test",
                                             algorithm="Lower threshold",
                                             values=parameters2)
        chosen_fields = [
            MeasurementEntry(
                name="Segmentation Volume",
                calculation_tree=Leaf(name="Volume",
                                      area=AreaType.ROI,
                                      per_component=PerComponent.No),
            ),
            MeasurementEntry(
                name="Segmentation Volume/Mask Volume",
                calculation_tree=Node(
                    left=Leaf(name="Volume",
                              area=AreaType.ROI,
                              per_component=PerComponent.No),
                    op="/",
                    right=Leaf(name="Volume",
                               area=AreaType.Mask,
                               per_component=PerComponent.No),
                ),
            ),
            MeasurementEntry(
                "Segmentation Components Number",
                calculation_tree=Leaf("Components number",
                                      area=AreaType.ROI,
                                      per_component=PerComponent.No),
            ),
            MeasurementEntry(
                "Mask Volume per component",
                calculation_tree=Leaf("Volume",
                                      area=AreaType.Mask,
                                      per_component=PerComponent.Yes),
            ),
        ]
        statistic = MeasurementProfile(name="base_measure2",
                                       chosen_fields=chosen_fields[:],
                                       name_prefix="aa_")
        statistic_calculate2 = MeasurementCalculate(
            channel=0,
            units=Units.µm,
            measurement_profile=statistic,
            name_prefix="")
        chosen_fields.append(
            MeasurementEntry(
                "Segmentation Volume per component",
                calculation_tree=Leaf("Volume",
                                      area=AreaType.ROI,
                                      per_component=PerComponent.Yes),
            ))
        statistic = MeasurementProfile(name="base_measure3",
                                       chosen_fields=chosen_fields[:],
                                       name_prefix="bb_")
        statistic_calculate3 = MeasurementCalculate(
            channel=0,
            units=Units.µm,
            measurement_profile=statistic,
            name_prefix="")
        tree = CalculationTree(
            RootType.Image,
            [
                CalculationTree(
                    mask_suffix,
                    [
                        CalculationTree(
                            segmentation,
                            [
                                CalculationTree(statistic_calculate, []),
                                CalculationTree(
                                    mask_create,
                                    [
                                        CalculationTree(
                                            segmentation2,
                                            [
                                                CalculationTree(
                                                    statistic_calculate2, []),
                                                CalculationTree(
                                                    statistic_calculate3, []),
                                            ],
                                        ),
                                    ],
                                ),
                            ],
                        )
                    ],
                )
            ],
        )
        return CalculationPlan(tree=tree, name="test")
Esempio n. 26
0
def mask_property():
    return MaskProperty(RadiusType.NO, 0, RadiusType.NO, 0, False, False,
                        False)