Exemplo n.º 1
0
def test_pipeline(image, algorithm_parameters, mask_property, tmp_path,
                  use_mask):
    elem = SegmentationPipelineElement(
        segmentation=ROIExtractionProfile(
            name="",
            algorithm=algorithm_parameters["algorithm_name"],
            values=algorithm_parameters["values"]),
        mask_property=mask_property,
    )
    algorithm_parameters = deepcopy(algorithm_parameters)
    algorithm_parameters["values"]["channel"] = 1
    pipeline = SegmentationPipeline(
        name="",
        segmentation=ROIExtractionProfile(
            name="",
            algorithm=algorithm_parameters["algorithm_name"],
            values=algorithm_parameters["values"]),
        mask_history=[elem],
    )
    mask = np.ones(image.get_channel(0).shape,
                   dtype=np.uint8) if use_mask else None
    result = calculate_pipeline(image, mask, pipeline, lambda x, y: None)
    assert np.max(result.roi) == 2
    pt = ProjectTuple(
        file_path=image.file_path,
        image=image,
        roi=result.roi,
        mask=result.mask,
        history=result.history,
        algorithm_parameters=algorithm_parameters,
    )
    SaveProject.save(tmp_path / "project.tgz", pt)
    assert os.path.exists(tmp_path / "project.tgz")
    loaded = LoadProject.load([tmp_path / "project.tgz"])
    assert np.all(loaded.roi == result.roi)
Exemplo n.º 2
0
def test_pipeline(image, algorithm_parameters, mask_property, tmp_path):
    elem = SegmentationPipelineElement(
        segmentation=SegmentationProfile(
            name="",
            algorithm=algorithm_parameters["algorithm_name"],
            values=algorithm_parameters["values"]),
        mask_property=mask_property,
    )
    algorithm_parameters = deepcopy(algorithm_parameters)
    algorithm_parameters["values"]["channel"] = 1
    pipeline = SegmentationPipeline(
        name="",
        segmentation=SegmentationProfile(
            name="",
            algorithm=algorithm_parameters["algorithm_name"],
            values=algorithm_parameters["values"]),
        mask_history=[elem],
    )
    result = calculate_pipeline(image, None, pipeline, lambda x, y: None)
    assert np.max(result.segmentation) == 2
    pt = ProjectTuple(
        file_path=image.file_path,
        image=image,
        segmentation=result.segmentation,
        mask=result.mask,
        history=result.history,
        algorithm_parameters=algorithm_parameters,
    )
    SaveProject.save(tmp_path / "project.tgz", pt)
    assert os.path.exists(tmp_path / "project.tgz")
    loaded = LoadProject.load([tmp_path / "project.tgz"])
    assert np.all(loaded.segmentation == result.segmentation)
Exemplo n.º 3
0
 def run(self):
     try:
         self.result = calculate_pipeline(
             image=self.image, mask=self.mask, pipeline=self.pipeline, report_fun=self.info_function
         )
     except Exception as e:  # pylint: disable=W0703
         self.error_signal.emit(e)
    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)