mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-18 12:40:14 +08:00
Added a second example to the edge filtering gallery example, focusing on
the difference between Scharr and Sobel filters.
This commit is contained in:
@@ -8,10 +8,11 @@ They are discrete differentiation operators, computing an approximation of the
|
||||
gradient of the image intensity function.
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage.data import camera
|
||||
from skimage.filters import roberts, sobel
|
||||
from skimage.filters import roberts, sobel, scharr
|
||||
|
||||
|
||||
image = camera()
|
||||
@@ -28,4 +29,49 @@ ax1.imshow(edge_sobel, cmap=plt.cm.gray)
|
||||
ax1.set_title('Sobel Edge Detection')
|
||||
ax1.axis('off')
|
||||
|
||||
plt.tight_layout()
|
||||
|
||||
"""
|
||||
.. image:: PLOT2RST.current_figure
|
||||
|
||||
Different operators compute different finite-difference approximations of the
|
||||
gradient. For example, the Scharr filter results in a better rotational
|
||||
variance than other filters such as the Sobel filter. The difference between
|
||||
the two filters is illustrated below on an image that is the discretization of
|
||||
a rotation-invariant continuous function. The discrepancy between the two
|
||||
filters is stronger for regions of the image where the direction of the
|
||||
gradient is close to diagonals, and for regions with high spatial frequencies.
|
||||
"""
|
||||
|
||||
x, y = np.ogrid[:100, :100]
|
||||
# Rotation-invariant image with different spatial frequencies
|
||||
img = np.exp(1j * np.hypot(x, y)**1.3 / 20.).real
|
||||
|
||||
edge_sobel = sobel(img)
|
||||
edge_scharr = scharr(img)
|
||||
|
||||
fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)
|
||||
|
||||
ax0.imshow(edge_sobel, cmap=plt.cm.gray)
|
||||
ax0.set_title('Sobel Edge Detection')
|
||||
ax0.axis('off')
|
||||
|
||||
ax1.imshow(edge_scharr, cmap=plt.cm.gray)
|
||||
ax1.set_title('Scharr Edge Detection')
|
||||
ax1.axis('off')
|
||||
|
||||
ax2.imshow(img, cmap=plt.cm.gray)
|
||||
ax2.set_title('Original image')
|
||||
ax2.axis('off')
|
||||
|
||||
ax3.imshow(edge_scharr - edge_sobel, cmap=plt.cm.jet)
|
||||
ax3.set_title('difference (Scharr - Sobel)')
|
||||
ax3.axis('off')
|
||||
|
||||
plt.tight_layout()
|
||||
|
||||
plt.show()
|
||||
|
||||
"""
|
||||
.. image:: PLOT2RST.current_figure
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user