コード例 #1
0
 def test_reversed_base_mu(self):
     image = np.zeros((10, 10, 10), dtype=np.uint8)
     image[2:8, 2:8, 2:8] = 10
     res = calculate_mu(image, 8, 2, MuType.base_mu)
     assert np.all(res == (image == 0).astype(np.float64))
     res = calculate_mu(image, 15, 5, MuType.base_mu)
     assert np.all(res == ((20 - image) / 20).astype(np.float64))
     image[4:6, 4:6, 4:6] = 20
     res = calculate_mu(image, 15, 5, MuType.base_mu)
     assert np.all(res == (20 - image) / 20)
コード例 #2
0
 def test_reversed_reflection_mu(self):
     image = np.zeros((10, 10, 10), dtype=np.uint8)
     image[2:8, 2:8, 2:8] = 10
     res = calculate_mu(image, 8, 2, MuType.reflection_mu)
     assert np.all(res == np.ones(image.shape, dtype=np.float64))
     res = calculate_mu(image, 15, 5, MuType.reflection_mu)
     assert np.all(res == (20 - image) / 20)
     image[4:6, 4:6, 4:6] = 20
     res = calculate_mu(image, 15, 5, MuType.reflection_mu)
     assert np.all(res == np.ones(image.shape, dtype=np.float64) -
                   (image == 10) * 0.5)
コード例 #3
0
 def test_reversed_base_mu_masked(self):
     image = np.zeros((10, 10, 10), dtype=np.uint8)
     image[2:8, 2:8, 2:8] = 10
     mask = image > 0
     res = calculate_mu(image, 8, 2, MuType.base_mu, mask)
     assert np.all(res == np.zeros(image.shape, dtype=np.float64))
     res = calculate_mu(image, 15, 5, MuType.base_mu, mask)
     assert np.all(res == mask * 0.5)
     image[4:6, 4:6, 4:6] = 20
     res = calculate_mu(image, 15, 5, MuType.base_mu, mask)
     assert np.all(res == (mask * (image < 20)) * 0.5)
コード例 #4
0
 def test_base_mu_masked(self):
     image = np.zeros((10, 10, 10), dtype=np.uint8)
     image[2:8, 2:8, 2:8] = 10
     res = calculate_mu(image, 2, 8, MuType.base_mu, image > 0)
     assert np.all(res == (image > 0).astype(np.float64))
     res = calculate_mu(image, 5, 15, MuType.base_mu, image > 0)
     assert np.all(res == (image > 0).astype(np.float64) * 0.5)
     image[4:6, 4:6, 4:6] = 20
     res = calculate_mu(image, 5, 15, MuType.base_mu, image > 0)
     assert np.all(res == ((image > 0).astype(np.float64) +
                           (image > 15).astype(np.float64)) * 0.5)
コード例 #5
0
 def test_reversed_reflection_mu_masked(self):
     image = np.zeros((10, 10, 10), dtype=np.uint8)
     image[2:8, 2:8, 2:8] = 10
     mask = image > 0
     res = calculate_mu(image, 8, 2, MuType.reflection_mu, mask)
     assert np.all(res == mask * 1.0)
     res = calculate_mu(image, 15, 5, MuType.reflection_mu, mask)
     assert np.all(res == ((20 - image) / 20) * mask)
     image[4:6, 4:6, 4:6] = 20
     res = calculate_mu(image, 15, 5, MuType.reflection_mu, mask)
     assert np.all(res == (np.ones(image.shape, dtype=np.float64) -
                           (image == 10) * 0.5) * mask)
コード例 #6
0
ファイル: watershed.py プロジェクト: 4DNucleome/PartSeg
    def sprawl(
        cls,
        sprawl_area: np.ndarray,
        core_objects: np.ndarray,
        data: np.ndarray,
        components_num: int,
        spacing,
        side_connection: bool,
        operator: Callable[[Any, Any], bool],
        arguments: dict,
        lower_bound,
        upper_bound,
    ):
        if components_num > 250:
            raise SegmentationLimitException("Current implementation of MSO do not support more than 250 components")
        mso = PyMSO()
        neigh, dist = calculate_distances_array(spacing, get_neigh(side_connection))
        components_arr = np.copy(core_objects).astype(np.uint8)
        components_arr[components_arr > 0] += 1
        components_arr[sprawl_area == 0] = 1
        mso.set_neighbourhood(neigh, dist)
        mso.set_components(components_arr, components_num + 1)
        mso.set_use_background(False)
        try:
            mu_array = calculate_mu(data.copy("C"), lower_bound, upper_bound, MuType.base_mu)
        except OverflowError:
            raise SegmentationLimitException("Wrong range for ")
        if arguments["reflective"]:
            mu_array[mu_array < 0.5] = 1 - mu_array[mu_array < 0.5]
        mso.set_mu_array(mu_array)
        try:
            mso.run_MSO(arguments["step_limits"])
        except RuntimeError as e:
            if e.args[0] == "to many steps: constrained dilation":
                raise SegmentationLimitException(*e.args)
            raise

        # print("Steps: ", mso.steps_done(), file=sys.stderr)
        result = mso.get_result_catted()
        result[result > 0] -= 1
        return result
コード例 #7
0
 def test_reshape(self):
     image = np.zeros((40, 150, 120), dtype=np.uint16)
     image[2:-2, 2:-2, 2:-2] = 30
     res = calculate_mu(image, 20, 40, MuType.base_mu)
     assert np.all(res == (image > 0) * 0.5)