mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-07 11:28:14 +08:00
Updated Implementation of Roberts Algorithm
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage.data import camera
|
||||
from skimage.filter import roberts,sobel
|
||||
|
||||
image = camera()
|
||||
edge_roberts = roberts(image)
|
||||
edge_sobel = sobel(image)
|
||||
|
||||
plt.figure(figsize=(8, 2.5))
|
||||
plt.subplot(1, 2, 1)
|
||||
plt.imshow(edge_roberts, cmap=plt.cm.gray)
|
||||
plt.title('Roberts Edge Detection')
|
||||
plt.axis('off')
|
||||
|
||||
plt.subplot(1, 2, 2)
|
||||
plt.imshow(edge_sobel, cmap=plt.cm.gray)
|
||||
plt.title('Sobel Edge Detection')
|
||||
plt.axis('off')
|
||||
|
||||
|
||||
plt.show()
|
||||
@@ -2,7 +2,7 @@ from .lpi_filter import *
|
||||
from .ctmf import median_filter
|
||||
from ._canny import canny
|
||||
from .edges import (sobel, hsobel, vsobel, scharr, hscharr, vscharr, prewitt,
|
||||
hprewitt, vprewitt)
|
||||
hprewitt, vprewitt, roberts , pdroberts, ndroberts)
|
||||
from ._denoise import denoise_tv_chambolle, tv_denoise
|
||||
from ._denoise_cy import denoise_bilateral, denoise_tv_bregman
|
||||
from ._rank_order import rank_order
|
||||
|
||||
@@ -338,3 +338,91 @@ def vprewitt(image, mask=None):
|
||||
[1, 0, -1],
|
||||
[1, 0, -1]]).astype(float) / 3.0))
|
||||
return _mask_filter_result(result, mask)
|
||||
|
||||
|
||||
def roberts(image, mask=None):
|
||||
"""Find the edge magnitude using Roberts' Cross Operator.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
image : 2-D array
|
||||
Image to process.
|
||||
mask : 2-D array, optional
|
||||
An optional mask to limit the application to a certain area.
|
||||
Note that pixels surrounding masked regions are also masked to
|
||||
prevent masked regions from affecting the result.
|
||||
|
||||
Returns
|
||||
-------
|
||||
output : ndarray
|
||||
The Roberts' Cross edge map.
|
||||
"""
|
||||
return np.sqrt(pdroberts(image, mask)**2 + ndroberts(image, mask)**2)
|
||||
|
||||
|
||||
def pdroberts(image, mask=None):
|
||||
"""Find the cross edges of an image using the Roberts' Cross operator.
|
||||
The kernel is applied to the input image, to produce separate measurements
|
||||
of the gradient component one orientation.
|
||||
Parameters
|
||||
----------
|
||||
image : 2-D array
|
||||
Image to process.
|
||||
mask : 2-D array, optional
|
||||
An optional mask to limit the application to a certain area.
|
||||
Note that pixels surrounding masked regions are also masked to
|
||||
prevent masked regions from affecting the result.
|
||||
|
||||
Returns
|
||||
-------
|
||||
output : ndarray
|
||||
The Robert edge map.
|
||||
|
||||
Notes
|
||||
-----
|
||||
We use the following kernel and return the absolute value of the
|
||||
result at each point::
|
||||
|
||||
1 0
|
||||
0 -1
|
||||
|
||||
"""
|
||||
image = img_as_float(image)
|
||||
result = np.abs(convolve(image,
|
||||
np.array([[ 1, 0],
|
||||
[ 0, -1]]).astype(float) / 1.0 ))
|
||||
return _mask_filter_result(result, mask)
|
||||
|
||||
|
||||
def ndroberts(image, mask=None):
|
||||
"""Find the cross edges of an image using the Roberts' Cross operator.
|
||||
The kernel is applied to the input image, to produce separate measurements
|
||||
of the gradient component one orientation.
|
||||
Parameters
|
||||
----------
|
||||
image : 2-D array
|
||||
Image to process.
|
||||
mask : 2-D array, optional
|
||||
An optional mask to limit the application to a certain area.
|
||||
Note that pixels surrounding masked regions are also masked to
|
||||
prevent masked regions from affecting the result.
|
||||
|
||||
Returns
|
||||
-------
|
||||
output : ndarray
|
||||
The Robert edge map.
|
||||
|
||||
Notes
|
||||
-----
|
||||
We use the following kernel and return the absolute value of the
|
||||
result at each point::
|
||||
|
||||
0 1
|
||||
-1 0
|
||||
|
||||
"""
|
||||
image = img_as_float(image)
|
||||
result = np.abs(convolve(image,
|
||||
np.array([[0, 1],
|
||||
[-1, 0]]).astype(float) / 1.0))
|
||||
return _mask_filter_result(result, mask)
|
||||
|
||||
Reference in New Issue
Block a user