Exemplo n.º 1
0
def test_uint16():
    im16, eroded16, dilated16, opened16, closed16 = (
                    map(img_as_uint, [im, eroded, dilated, opened, closed]))
    np.testing.assert_allclose(grey.erosion(im16), eroded16)
    np.testing.assert_allclose(grey.dilation(im16), dilated16)
    np.testing.assert_allclose(grey.opening(im16), opened16)
    np.testing.assert_allclose(grey.closing(im16), closed16)
Exemplo n.º 2
0
def test_uint16():
    im16, eroded16, dilated16, opened16, closed16 = (
        map(img_as_uint, [im, eroded, dilated, opened, closed]))
    np.testing.assert_allclose(grey.erosion(im16), eroded16)
    np.testing.assert_allclose(grey.dilation(im16), dilated16)
    np.testing.assert_allclose(grey.opening(im16), opened16)
    np.testing.assert_allclose(grey.closing(im16), closed16)
Exemplo n.º 3
0
    def morph_imgs(self, set=[], labels=[]):
        """Adds dilated and closed Images"""
        print('Morphing images...')
        out_set = []
        out_labels = []
        for i in range(0, len(set)):
            out_set.append(set[i])
            out_labels.append(labels[i])

            img_dilated = dilation(set[i])
            out_set.append(img_dilated)
            out_labels.append(labels[i])

            img_closed = closing(set[i])
            out_set.append(img_closed)
            out_labels.append(labels[i])

            img_eroded = erosion(set[i])
            out_set.append(img_eroded)
            out_labels.append(labels[i])

            img_opened = opening(set[i])
            out_set.append(img_opened)
            out_labels.append(labels[i])
        return np.asarray(out_set), np.asarray(out_labels)
Exemplo n.º 4
0
def test_uint16():
    with expected_warnings(['Possible precision loss']):
        im16, eroded16, dilated16, opened16, closed16 = (map(
            img_as_uint, [im, eroded, dilated, opened, closed]))
    np.testing.assert_allclose(grey.erosion(im16), eroded16)
    np.testing.assert_allclose(grey.dilation(im16), dilated16)
    np.testing.assert_allclose(grey.opening(im16), opened16)
    np.testing.assert_allclose(grey.closing(im16), closed16)
Exemplo n.º 5
0
    def _test_image(self, image):
        with expected_warnings(['precision loss']):
            result_opening = grey.opening(image, self.disk)
        testing.assert_equal(result_opening, self.expected_opening)

        with expected_warnings(['precision loss']):
            result_closing = grey.closing(image, self.disk)
        testing.assert_equal(result_closing, self.expected_closing)
Exemplo n.º 6
0
def test_uint16():
    with expected_warnings(['Possible precision loss']):
        im16, eroded16, dilated16, opened16, closed16 = (
            map(img_as_uint, [im, eroded, dilated, opened, closed]))
    np.testing.assert_allclose(grey.erosion(im16), eroded16)
    np.testing.assert_allclose(grey.dilation(im16), dilated16)
    np.testing.assert_allclose(grey.opening(im16), opened16)
    np.testing.assert_allclose(grey.closing(im16), closed16)
Exemplo n.º 7
0
def test_3d_fallback_default_selem():
    # 3x3x3 cube inside a 7x7x7 image:
    image = np.zeros((7, 7, 7), bool)
    image[2:-2, 2:-2, 2:-2] = 1

    opened = grey.opening(image)

    # expect a "hyper-cross" centered in the 5x5x5:
    image_expected = np.zeros((7, 7, 7), dtype=bool)
    image_expected[2:5, 2:5, 2:5] = ndi.generate_binary_structure(3, 1)
    assert_array_equal(opened, image_expected)
Exemplo n.º 8
0
def test_3d_fallback_default_selem():
    # 3x3x3 cube inside a 7x7x7 image:
    image = np.zeros((7, 7, 7), np.bool)
    image[2:-2, 2:-2, 2:-2] = 1

    opened = grey.opening(image)

    # expect a "hyper-cross" centered in the 5x5x5:
    image_expected = np.zeros((7, 7, 7), dtype=bool)
    image_expected[2:5, 2:5, 2:5] = ndi.generate_binary_structure(3, 1)
    testing.assert_array_equal(opened, image_expected)
Exemplo n.º 9
0
def test_2d_ndimage_equivalence():
    image = np.zeros((9, 9), np.uint8)
    image[2:-2, 2:-2] = 128
    image[3:-3, 3:-3] = 196
    image[4, 4] = 255

    opened = grey.opening(image)
    closed = grey.closing(image)

    selem = ndi.generate_binary_structure(2, 1)
    ndimage_opened = ndi.grey_opening(image, footprint=selem)
    ndimage_closed = ndi.grey_closing(image, footprint=selem)

    assert_array_equal(opened, ndimage_opened)
    assert_array_equal(closed, ndimage_closed)
Exemplo n.º 10
0
def test_2d_ndimage_equivalence():
    image = np.zeros((9, 9), np.uint8)
    image[2:-2, 2:-2] = 128
    image[3:-3, 3:-3] = 196
    image[4, 4] = 255

    opened = grey.opening(image)
    closed = grey.closing(image)

    selem = ndi.generate_binary_structure(2, 1)
    ndimage_opened = ndi.grey_opening(image, footprint=selem)
    ndimage_closed = ndi.grey_closing(image, footprint=selem)

    testing.assert_array_equal(opened, ndimage_opened)
    testing.assert_array_equal(closed, ndimage_closed)
Exemplo n.º 11
0
def test_float():
    np.testing.assert_allclose(grey.erosion(im), eroded)
    np.testing.assert_allclose(grey.dilation(im), dilated)
    np.testing.assert_allclose(grey.opening(im), opened)
    np.testing.assert_allclose(grey.closing(im), closed)
Exemplo n.º 12
0
 def test_open_black_pixel(self):
     for s in self.selems:
         grey_open = grey.opening(self.black_pixel, s)
         assert np.all(grey_open == self.black_pixel)
Exemplo n.º 13
0
 def test_open_white_pixel(self):
     for s in self.selems:
         assert np.all(grey.opening(self.white_pixel, s) == 0)
Exemplo n.º 14
0
def test_float():
    np.testing.assert_allclose(grey.erosion(im), eroded)
    np.testing.assert_allclose(grey.dilation(im), dilated)
    np.testing.assert_allclose(grey.opening(im), opened)
    np.testing.assert_allclose(grey.closing(im), closed)
Exemplo n.º 15
0
def test_binary_opening():
    strel = selem.square(3)
    binary_res = binary.binary_opening(bw_img, strel)
    with expected_warnings(['precision loss']):
        grey_res = img_as_bool(grey.opening(bw_img, strel))
    testing.assert_array_equal(binary_res, grey_res)
Exemplo n.º 16
0
    def _test_image(self, image):
        result_opening = grey.opening(image, self.disk)
        testing.assert_equal(result_opening, self.expected_opening)

        result_closing = grey.closing(image, self.disk)
        testing.assert_equal(result_closing, self.expected_closing)
Exemplo n.º 17
0
 def test_open_black_pixel(self):
     for s in self.selems:
         grey_open = grey.opening(self.black_pixel, s)
         assert np.all(grey_open == self.black_pixel)
Exemplo n.º 18
0
def test_binary_opening():
    strel = selem.square(3)
    binary_res = binary.binary_opening(bw_img, strel)
    grey_res = img_as_bool(grey.opening(bw_img, strel))
    testing.assert_array_equal(binary_res, grey_res)
Exemplo n.º 19
0
def test_binary_opening():
    strel = selem.square(3)
    binary_res = binary.binary_opening(bw_lena, strel)
    grey_res = img_as_bool(grey.opening(bw_lena, strel))
    testing.assert_array_equal(binary_res, grey_res)
Exemplo n.º 20
0
    def _test_image(self, image):
        result_opening = grey.opening(image, self.disk)
        testing.assert_equal(result_opening, self.expected_opening)

        result_closing = grey.closing(image, self.disk)
        testing.assert_equal(result_closing, self.expected_closing)
Exemplo n.º 21
0
 def test_open_white_pixel(self):
     for s in self.selems:
         assert np.all(grey.opening(self.white_pixel, s) == 0)
Exemplo n.º 22
0
def test_binary_opening():
    strel = selem.square(3)
    binary_res = binary.binary_opening(bw_lena, strel)
    grey_res = grey.opening(bw_lena, strel)
    testing.assert_array_equal(binary_res, grey_res)