def test_hsobel_horizontal(): """Horizontal Sobel on an edge should be a horizontal line.""" i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) result = filters.hsobel(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))
""" Created on Tue Jun 13 19:56:42 2017 @author: user """ import matplotlib.pyplot as plt import numpy as np from skimage import filters as filters import skimage.io as io import scipy.ndimage as ndi from skimage import feature w = io.imread('x-ray.jpg', "gray") wh = filters.hsobel(w) wv = filters.vsobel(w) wall = filters.sobel(w) fig = plt.figure(figsize=(15, 8)) ax1 = fig.add_subplot(2, 2, 1) io.imshow(w) plt.title('original', fontsize=10) ax1 = fig.add_subplot(2, 2, 2) plt.imshow(wh * 10, 'gray') plt.title('Sobel (x direction)', fontsize=10) ax1 = fig.add_subplot(2, 2, 3) plt.imshow(wv * 10, 'gray') plt.title('Sobel (y direction)', fontsize=10) ax1 = fig.add_subplot(2, 2, 4) plt.imshow(wall * 10, 'gray') plt.title('Sobel filter', fontsize=10)
# filter 1: horizontal Sobel filter import matplotlib.pyplot as plt from skimage import data , filters camera = data.camera() hsobel_camera = filters.hsobel(camera) plt.figure(figsize=(8, 4)) plt.subplot(121) plt.imshow(camera) plt.subplot(122) plt.imshow(hsobel_camera) plt.tight_layout() plt.show()
def test_hsobel_vertical(): """Horizontal Sobel on a vertical edge should be zero.""" i, j = np.mgrid[-5:6, -5:6] image = (j >= 0).astype(float) * np.sqrt(2) result = filters.hsobel(image) assert_allclose(result, 0, atol=1e-10)
def test_hsobel_mask(): """Horizontal Sobel on a masked array should be zero.""" np.random.seed(0) result = filters.hsobel(np.random.uniform(size=(10, 10)), np.zeros((10, 10), bool)) assert (np.all(result == 0))
def test_hsobel_zeros(): """Horizontal sobel on an array of all zeros.""" result = filters.hsobel(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0))
""" Computing horizontal gradients with the Sobel filter ===================================================== This example illustrates the use of the horizontal Sobel filter, to compute horizontal gradients. """ from skimage import data # scikit-image has changes its API try: from skimage import filters except ImportError: from skimage import filter as filters import matplotlib.pyplot as plt text = data.text() hsobel_text = filters.hsobel(text) plt.figure(figsize=(12, 3)) plt.subplot(121) plt.imshow(text, cmap='gray', interpolation='nearest') plt.axis('off') plt.subplot(122) plt.imshow(hsobel_text, cmap='spectral', interpolation='nearest') plt.axis('off') plt.tight_layout() plt.show()