Exemplo n.º 1
0
    def test_segmentation_clean_select_seed_component(self):
        selection = {(0, 0), (3, 3)}
        weight = 1
        original = Segmentation(selection, weight)

        new = original.clean({(3, 3)}, (5, 5))
        assert new == Segmentation({(3, 3)}, weight)
        assert original == Segmentation(selection, weight)
Exemplo n.º 2
0
    def test_segmentation_clean_fill_hole(self):
        selection = {(0, 0), (1, 0), (2, 0), (0, 1), (2, 1), (0, 2), (1, 2), (2, 2)}
        weight = 1
        original = Segmentation(selection, weight)

        new = original.clean(set(), (5, 5))
        assert new == Segmentation(
            {(0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2, 2)},
            weight,
        )
        assert original == Segmentation(selection, weight)
Exemplo n.º 3
0
    def test_hnccorr_segmentations_after_segment(self, H, MM,
                                                 mock_candidate_class):
        base_segmentation = Segmentation(set(), "segment")
        mock_candidate_class.return_value.segment.return_value = base_segmentation

        H.segment(MM)
        assert H.segmentations == [base_segmentation]

        H.segment(MM)
        assert H.segmentations == [base_segmentation]
Exemplo n.º 4
0
    def test_hnccorr_candidates_after_segment(self, H, MM,
                                              mock_candidate_class):
        base_segmentation = Segmentation(set(), "segment")
        mock_candidate_class.return_value.segment.return_value = base_segmentation

        assert H.candidates == []
        H.segment(MM)
        assert len(H.candidates) == 1
        assert H.candidates[0].segment() == base_segmentation

        H.segment(MM)
        assert len(H.candidates) == 1
        assert H.candidates[0].segment() == base_segmentation
Exemplo n.º 5
0
    def test_hnccor_exclude_previously_segmented_pixels(
            self, mock_seeder, dummy, mock_candidate_class):
        mock_seeder.next.side_effect = ("seed1", None)
        mock_candidate_class.return_value.segment.return_value = Segmentation(
            {"pixel"}, 1)
        H = HNCcorr(
            mock_seeder,
            "postprocessor",
            "mock_segmentor",
            "pos_seed_selector",
            "neg_seed_selector",
            "graph_constructor",
            mock_candidate_class,
            "patch",
            "embedding",
            "patch_size",
        )

        H.segment(dummy)

        mock_seeder.exclude_pixels.assert_called_once_with({"pixel"})
Exemplo n.º 6
0
def simple_segmentation():
    return Segmentation({(0, 1)}, 1.0)
Exemplo n.º 7
0
 def test_select_no_valid_candidates(self, postprocessor):
     assert (postprocessor.select([
         Segmentation({(0, 1)}, 0.5),
         Segmentation({(0, 0), (1, 0), (2, 0), (0, 1), (2, 1),
                       (0, 2)}, 0.5),
     ]) is None)
Exemplo n.º 8
0
 def test_select_preference(self, postprocessor):
     S1 = Segmentation({(0, 1), (0, 2), (0, 3)}, 0.5)
     S2 = Segmentation({(0, 1), (0, 2)}, 0.5)
     assert postprocessor.select([S1, S2]) == S1
Exemplo n.º 9
0
    def test_segmentation_equality_wrong_class(self):
        class FakeSegmentation:
            pass

        assert Segmentation({(0, 1)}, 0.5) != FakeSegmentation()
Exemplo n.º 10
0
 def test_segmentation_selection(self):
     assert Segmentation({(0, 1)}, 0.5).selection == {(0, 1)}
Exemplo n.º 11
0
 def test_segmentation_weight(self):
     assert Segmentation({0, 1}, 0.5).weight == 0.5
Exemplo n.º 12
0
def matlab_segmentation():
    return Segmentation(
        {
            # First 3 pixels are manually ADDED due to small differences in
            # implementation.
            (285, 433),
            (282, 432),
            (279, 440),
            # Solution MATLAB:
            (280, 433),
            (281, 433),
            (282, 433),
            (283, 433),
            (284, 433),
            (279, 434),
            (280, 434),
            (281, 434),
            (282, 434),
            (283, 434),
            (284, 434),
            (285, 434),
            (286, 434),
            (279, 435),
            (280, 435),
            (281, 435),
            (282, 435),
            (283, 435),
            (284, 435),
            (285, 435),
            (286, 435),
            (287, 435),
            (279, 436),
            (280, 436),
            (281, 436),
            (282, 436),
            (283, 436),
            (284, 436),
            (285, 436),
            (286, 436),
            (287, 436),
            (279, 437),
            (280, 437),
            (281, 437),
            (282, 437),
            (283, 437),
            (284, 437),
            (285, 437),
            (286, 437),
            (287, 437),
            (279, 438),
            (280, 438),
            (281, 438),
            (282, 438),
            (283, 438),
            (284, 438),
            (285, 438),
            (286, 438),
            (287, 438),
            (279, 439),
            (280, 439),
            (281, 439),
            (282, 439),
            (283, 439),
            (284, 439),
            (285, 439),
            (286, 439),
            (280, 440),
            (281, 440),
            (282, 440),
            (283, 440),
            (284, 440),
            (285, 440),
            (286, 440),
            (280, 441),
            (281, 441),
            (282, 441),
            (283, 441),
            (284, 441),
            (285, 441),
            (282, 442),
            (283, 442),
        },
        0.0,
    )