| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
|
| 4 |
import numbers |
| 5 |
|
| 6 |
import scipy.ndimage |
| 7 |
|
| 8 |
from ..dispatch._dispatch_ndfilters import dispatch_prewitt, dispatch_sobel |
| 9 |
from . import _utils |
| 10 |
|
| 11 |
__all__ = [ |
| 12 |
"prewitt", |
| 13 |
"sobel", |
| 14 |
] |
| 15 |
|
| 16 |
|
| 17 |
def _validate_axis(ndim, axis): |
| 18 |
if not isinstance(axis, numbers.Integral): |
| 19 |
raise ValueError("The axis must be of integral type.") |
| 20 |
if axis < -ndim or axis >= ndim: |
| 21 |
raise ValueError("The axis is out of range.") |
| 22 |
|
| 23 |
|
| 24 |
@_utils._update_wrapper(scipy.ndimage.prewitt) |
| 25 |
def prewitt(image, axis=-1, mode='reflect', cval=0.0): |
| 26 |
_validate_axis(image.ndim, axis) |
| 27 |
|
| 28 |
result = image.map_overlap( |
| 29 |
dispatch_prewitt(image), |
| 30 |
depth=(image.ndim * (1,)), |
| 31 |
boundary="none", |
| 32 |
dtype=image.dtype, |
| 33 |
meta=image._meta, |
| 34 |
axis=axis, |
| 35 |
mode=mode, |
| 36 |
cval=cval |
| 37 |
) |
| 38 |
|
| 39 |
return result |
| 40 |
|
| 41 |
|
| 42 |
@_utils._update_wrapper(scipy.ndimage.sobel) |
| 43 |
def sobel(image, axis=-1, mode='reflect', cval=0.0): |
| 44 |
_validate_axis(image.ndim, axis) |
| 45 |
|
| 46 |
result = image.map_overlap( |
| 47 |
dispatch_sobel(image), |
| 48 |
depth=(image.ndim * (1,)), |
| 49 |
boundary="none", |
| 50 |
dtype=image.dtype, |
| 51 |
meta=image._meta, |
| 52 |
axis=axis, |
| 53 |
mode=mode, |
| 54 |
cval=cval |
| 55 |
) |
| 56 |
|
| 57 |
return result |