コード例 #1
0
    def test_region_by_identifier(self):

        from jicbioimage.segment import SegmentedImage

        input_array = np.array([[0, 0, 0],
                                [1, 1, 1],
                                [2, 2, 2]])

        segmented_image = SegmentedImage.from_array(input_array)

        with self.assertRaises(ValueError):
            segmented_image.region_by_identifier(0)

        with self.assertRaises(ValueError):
            segmented_image.region_by_identifier(0.5)

        with self.assertRaises(ValueError):
            segmented_image.region_by_identifier(-1)

        from jicbioimage.segment import Region

        selected_region = segmented_image.region_by_identifier(1)

        self.assertTrue(isinstance(selected_region, Region))

        expected_output = Region.select_from_array(input_array, 1)
        self.assertTrue(np.array_equal(selected_region,
                                       expected_output))
コード例 #2
0
    def test_dilate(self):
        from jicbioimage.segment import Region

        test_array = np.array([[0, 0, 0, 0, 0],
                               [0, 0, 1, 1, 0],
                               [0, 1, 1, 0, 0],
                               [0, 1, 0, 0, 0],
                               [0, 0, 0, 0, 0]])

        region = Region(test_array)

        dilate_array = np.array([[0, 0, 1, 1, 0],
                                 [0, 1, 1, 1, 1],
                                 [1, 1, 1, 1, 0],
                                 [1, 1, 1, 0, 0],
                                 [0, 1, 0, 0, 0]], dtype=bool)

        self.assertTrue(np.array_equal(region.dilate(),
                                       dilate_array))
コード例 #3
0
    def test_region_select_from_array(self):
        from jicbioimage.segment import Region

        id_array = np.array([[0, 0, 0],
                             [1, 1, 1],
                             [2, 2, 2]])

        region_1 = Region.select_from_array(id_array, 1)

        self.assertFalse(region_1[0, 0])
        self.assertTrue(region_1[1, 0])
        self.assertFalse(region_1[2, 0])

        self.assertEqual(region_1.area, 3)
コード例 #4
0
    def test_background(self):

        from jicbioimage.segment import SegmentedImage

        input_array = np.array([[0, 0, 0],
                                [1, 1, 1],
                                [2, 2, 2]])

        segmented_image = SegmentedImage.from_array(input_array)

        from jicbioimage.segment import Region

        background = segmented_image.background

        expected_output = Region.select_from_array(input_array, 0)
        self.assertTrue(np.array_equal(background,
                                       expected_output))