def get_edges(img):
    edge = np.empty(img.shape)
    if len(img.shape) == 3:
        for i in range(3):
            edge[:, :, i] = imfilt.sobel(img[:, :, i])
    else:
        edge = imfilt.sobel(img)
    edge = rescale_intensity(edge)
    return edge
Example #2
0
    def test_convolution_upcast(self):
        i, j = np.mgrid[-5:6, -5:6]
        image = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy'))

        result1 = F.sobel(image)
        image = image.astype(float)
        result2 = F.sobel(image)

        assert_array_equal(result1, result2)
    def test_convolution_upcast(self):
        i, j = np.mgrid[-5:6, -5:6]
        image = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy'))

        result1 = F.sobel(image)
        image = image.astype(float)
        result2 = F.sobel(image)

        assert_array_equal(result1, result2)
Example #4
0
 def test_01_02_vertical(self):
     """Sobel on a vertical edge should be a vertical line"""
     i, j = np.mgrid[-5:6, -5:6]
     image = (j >= 0).astype(float)
     result = F.sobel(image)
     j[np.abs(i) == 5] = 10000
     assert (np.all(result[j == 0] == 1))
     assert (np.all(result[np.abs(j) > 1] == 0))
 def test_01_02_vertical(self):
     """Sobel on a vertical edge should be a vertical line"""
     i, j = np.mgrid[-5:6, -5:6]
     image = (j >= 0).astype(float)
     result = F.sobel(image)
     j[np.abs(i) == 5] = 10000
     assert (np.all(result[j == 0] == 1))
     assert (np.all(result[np.abs(j) > 1] == 0))
Example #6
0
 def test_01_01_horizontal(self):
     """Sobel on an edge should be a horizontal line"""
     i, j = np.mgrid[-5:6, -5:6]
     image = (i >= 0).astype(float)
     result = F.sobel(image)
     # Fudge the eroded points
     i[np.abs(j) == 5] = 10000
     assert (np.all(result[i == 0] == 1))
     assert (np.all(result[np.abs(i) > 1] == 0))
 def test_01_01_horizontal(self):
     """Sobel on an edge should be a horizontal line"""
     i, j = np.mgrid[-5:6, -5:6]
     image = (i >= 0).astype(float)
     result = F.sobel(image)
     # Fudge the eroded points
     i[np.abs(j) == 5] = 10000
     assert (np.all(result[i == 0] == 1))
     assert (np.all(result[np.abs(i) > 1] == 0))
Example #8
0
 def test_00_01_mask(self):
     """Sobel on a masked array should be zero"""
     np.random.seed(0)
     result = F.sobel(np.random.uniform(size=(10, 10)),
                      np.zeros((10, 10), bool))
     assert (np.all(result == 0))
Example #9
0
 def test_00_00_zeros(self):
     """Sobel on an array of all zeros"""
     result = F.sobel(np.zeros((10, 10)), np.ones((10, 10), bool))
     assert (np.all(result == 0))
Example #10
0
 def test_00_01_mask(self):
     """Sobel on a masked array should be zero"""
     np.random.seed(0)
     result = F.sobel(np.random.uniform(size=(10, 10)),
                      np.zeros((10, 10), bool))
     assert (np.all(result == 0))
Example #11
0
 def test_00_00_zeros(self):
     """Sobel on an array of all zeros"""
     result = F.sobel(np.zeros((10, 10)), np.ones((10, 10), bool))
     assert (np.all(result == 0))