From 811b6895cfc84dd4777da66c3a9c910f0520178e Mon Sep 17 00:00:00 2001 From: sumitbinnani Date: Fri, 2 Oct 2015 14:56:35 +0530 Subject: [PATCH] Refactoring ```skimage.filters.gabor_filter``` to ```skimage.filters.gabor``` Refactoring ```skimage.filters.gaussian_filter``` to ```skimage.filters.gaussian``` --- skimage/color/tests/test_adapt_rgb.py | 6 +++--- skimage/data/_binary_blobs.py | 4 ++-- skimage/filter/__init__.py | 8 ++++---- skimage/filters/__init__.py | 8 ++++---- skimage/filters/_gabor.py | 10 +++++----- skimage/filters/_gaussian.py | 12 ++++++------ skimage/filters/tests/test_gabor.py | 6 +++--- skimage/filters/tests/test_gaussian.py | 18 +++++++++--------- skimage/util/tests/test_apply_parallel.py | 14 +++++++------- 9 files changed, 43 insertions(+), 43 deletions(-) diff --git a/skimage/color/tests/test_adapt_rgb.py b/skimage/color/tests/test_adapt_rgb.py index 9e97b6b6..efe90977 100644 --- a/skimage/color/tests/test_adapt_rgb.py +++ b/skimage/color/tests/test_adapt_rgb.py @@ -12,7 +12,7 @@ COLOR_IMAGE = data.astronaut()[::5, ::5] GRAY_IMAGE = data.camera()[::5, ::5] SIGMA = 3 -smooth = partial(filters.gaussian_filter, sigma=SIGMA) +smooth = partial(filters.gaussian, sigma=SIGMA) assert_allclose = partial(np.testing.assert_allclose, atol=1e-8) @@ -23,7 +23,7 @@ def edges_each(image): @adapt_rgb(each_channel) def smooth_each(image, sigma): - return filters.gaussian_filter(image, sigma) + return filters.gaussian(image, sigma) @adapt_rgb(hsv_value) @@ -33,7 +33,7 @@ def edges_hsv(image): @adapt_rgb(hsv_value) def smooth_hsv(image, sigma): - return filters.gaussian_filter(image, sigma) + return filters.gaussian(image, sigma) @adapt_rgb(hsv_value) diff --git a/skimage/data/_binary_blobs.py b/skimage/data/_binary_blobs.py index f441fce2..83503151 100644 --- a/skimage/data/_binary_blobs.py +++ b/skimage/data/_binary_blobs.py @@ -1,5 +1,5 @@ import numpy as np -from ..filters import gaussian_filter +from ..filters import gaussian def binary_blobs(length=512, blob_size_fraction=0.1, n_dim=2, @@ -48,6 +48,6 @@ def binary_blobs(length=512, blob_size_fraction=0.1, n_dim=2, n_pts = max(int(1. / blob_size_fraction) ** n_dim, 1) points = (length * rs.rand(n_dim, n_pts)).astype(np.int) mask[[indices for indices in points]] = 1 - mask = gaussian_filter(mask, sigma=0.25 * length * blob_size_fraction) + mask = gaussian(mask, sigma=0.25 * length * blob_size_fraction) threshold = np.percentile(mask, 100 * (1 - volume_fraction)) return np.logical_not(mask < threshold) diff --git a/skimage/filter/__init__.py b/skimage/filter/__init__.py index b5981329..ab74ced7 100644 --- a/skimage/filter/__init__.py +++ b/skimage/filter/__init__.py @@ -12,7 +12,7 @@ del warn del skimage_deprecation from ..filters.lpi_filter import inverse, wiener, LPIFilter2D -from ..filters._gaussian import gaussian_filter +from ..filters._gaussian import gaussian from ..filters.edges import (sobel, hsobel, vsobel, sobel_h, sobel_v, scharr, hscharr, vscharr, scharr_h, scharr_v, prewitt, hprewitt, vprewitt, prewitt_h, prewitt_v, @@ -20,7 +20,7 @@ from ..filters.edges import (sobel, hsobel, vsobel, sobel_h, sobel_v, roberts_negative_diagonal, roberts_pos_diag, roberts_neg_diag) from ..filters._rank_order import rank_order -from ..filters._gabor import gabor_kernel, gabor_filter +from ..filters._gabor import gabor_kernel, gabor from ..filters.thresholding import (threshold_adaptive, threshold_otsu, threshold_yen, threshold_isodata) from ..filters import rank @@ -46,7 +46,7 @@ def canny(*args, **kwargs): __all__ = ['inverse', 'wiener', 'LPIFilter2D', - 'gaussian_filter', + 'gaussian', 'median', 'canny', 'sobel', @@ -74,7 +74,7 @@ __all__ = ['inverse', 'denoise_tv_bregman', 'rank_order', 'gabor_kernel', - 'gabor_filter', + 'gabor', 'threshold_adaptive', 'threshold_otsu', 'threshold_yen', diff --git a/skimage/filters/__init__.py b/skimage/filters/__init__.py index 7cffb140..8878f26b 100644 --- a/skimage/filters/__init__.py +++ b/skimage/filters/__init__.py @@ -1,5 +1,5 @@ from .lpi_filter import inverse, wiener, LPIFilter2D -from ._gaussian import gaussian_filter +from ._gaussian import gaussian from .edges import (sobel, hsobel, vsobel, sobel_h, sobel_v, scharr, hscharr, vscharr, scharr_h, scharr_v, prewitt, hprewitt, vprewitt, prewitt_h, prewitt_v, @@ -7,7 +7,7 @@ from .edges import (sobel, hsobel, vsobel, sobel_h, sobel_v, roberts_negative_diagonal, roberts_pos_diag, roberts_neg_diag) from ._rank_order import rank_order -from ._gabor import gabor_kernel, gabor_filter +from ._gabor import gabor_kernel, gabor from .thresholding import (threshold_adaptive, threshold_otsu, threshold_yen, threshold_isodata, threshold_li) from . import rank @@ -33,7 +33,7 @@ def canny(*args, **kwargs): __all__ = ['inverse', 'wiener', 'LPIFilter2D', - 'gaussian_filter', + 'gaussian', 'median', 'canny', 'sobel', @@ -61,7 +61,7 @@ __all__ = ['inverse', 'denoise_tv_bregman', 'rank_order', 'gabor_kernel', - 'gabor_filter', + 'gabor', 'threshold_adaptive', 'threshold_otsu', 'threshold_yen', diff --git a/skimage/filters/_gabor.py b/skimage/filters/_gabor.py index 4d249d2c..43f0e9de 100644 --- a/skimage/filters/_gabor.py +++ b/skimage/filters/_gabor.py @@ -3,7 +3,7 @@ from scipy import ndimage as ndi from .._shared.utils import assert_nD -__all__ = ['gabor_kernel', 'gabor_filter'] +__all__ = ['gabor_kernel', 'gabor'] def _sigma_prefactor(bandwidth): @@ -94,7 +94,7 @@ def gabor_kernel(frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, return g -def gabor_filter(image, frequency, theta=0, bandwidth=1, sigma_x=None, +def gabor(image, frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, n_stds=3, offset=0, mode='reflect', cval=0): """Return real and imaginary responses to Gabor filter. @@ -148,19 +148,19 @@ def gabor_filter(image, frequency, theta=0, bandwidth=1, sigma_x=None, Examples -------- - >>> from skimage.filter import gabor_filter + >>> from skimage.filter import gabor >>> from skimage import data, io >>> from matplotlib import pyplot as plt # doctest: +SKIP >>> image = data.coins() >>> # detecting edges in a coin image - >>> filt_real, filt_imag = gabor_filter(image, frequency=0.6) + >>> filt_real, filt_imag = gabor(image, frequency=0.6) >>> plt.figure() # doctest: +SKIP >>> io.imshow(filt_real) # doctest: +SKIP >>> io.show() # doctest: +SKIP >>> # less sensitivity to finer details with the lower frequency kernel - >>> filt_real, filt_imag = gabor_filter(image, frequency=0.1) + >>> filt_real, filt_imag = gabor(image, frequency=0.1) >>> plt.figure() # doctest: +SKIP >>> io.imshow(filt_real) # doctest: +SKIP >>> io.show() # doctest: +SKIP diff --git a/skimage/filters/_gaussian.py b/skimage/filters/_gaussian.py index 85b572ca..21fdfde8 100644 --- a/skimage/filters/_gaussian.py +++ b/skimage/filters/_gaussian.py @@ -6,10 +6,10 @@ import warnings from ..util import img_as_float from ..color import guess_spatial_dimensions -__all__ = ['gaussian_filter'] +__all__ = ['gaussian'] -def gaussian_filter(image, sigma, output=None, mode='nearest', cval=0, +def gaussian(image, sigma, output=None, mode='nearest', cval=0, multichannel=None): """Multi-dimensional Gaussian filter @@ -66,23 +66,23 @@ def gaussian_filter(image, sigma, output=None, mode='nearest', cval=0, array([[ 0., 0., 0.], [ 0., 1., 0.], [ 0., 0., 0.]]) - >>> gaussian_filter(a, sigma=0.4) # mild smoothing + >>> gaussian(a, sigma=0.4) # mild smoothing array([[ 0.00163116, 0.03712502, 0.00163116], [ 0.03712502, 0.84496158, 0.03712502], [ 0.00163116, 0.03712502, 0.00163116]]) - >>> gaussian_filter(a, sigma=1) # more smooting + >>> gaussian(a, sigma=1) # more smooting array([[ 0.05855018, 0.09653293, 0.05855018], [ 0.09653293, 0.15915589, 0.09653293], [ 0.05855018, 0.09653293, 0.05855018]]) >>> # Several modes are possible for handling boundaries - >>> gaussian_filter(a, sigma=1, mode='reflect') + >>> gaussian(a, sigma=1, mode='reflect') array([[ 0.08767308, 0.12075024, 0.08767308], [ 0.12075024, 0.16630671, 0.12075024], [ 0.08767308, 0.12075024, 0.08767308]]) >>> # For RGB images, each is filtered separately >>> from skimage.data import astronaut >>> image = astronaut() - >>> filtered_img = gaussian_filter(image, sigma=1, multichannel=True) + >>> filtered_img = gaussian(image, sigma=1, multichannel=True) """ diff --git a/skimage/filters/tests/test_gabor.py b/skimage/filters/tests/test_gabor.py index 34b26e1f..bc49fde8 100644 --- a/skimage/filters/tests/test_gabor.py +++ b/skimage/filters/tests/test_gabor.py @@ -2,7 +2,7 @@ import numpy as np from numpy.testing import (assert_equal, assert_almost_equal, assert_array_almost_equal) -from skimage.filters._gabor import gabor_kernel, gabor_filter, _sigma_prefactor +from skimage.filters._gabor import gabor_kernel, gabor, _sigma_prefactor def test_gabor_kernel_size(): @@ -59,13 +59,13 @@ def test_gabor_kernel_theta(): np.abs(kernel180)) -def test_gabor_filter(): +def test_gabor(): Y, X = np.mgrid[:40, :40] frequencies = (0.1, 0.3) wave_images = [np.sin(2 * np.pi * X * f) for f in frequencies] def match_score(image, frequency): - gabor_responses = gabor_filter(image, frequency) + gabor_responses = gabor(image, frequency) return np.mean(np.hypot(*gabor_responses)) # Gabor scores: diagonals are frequency-matched, off-diagonals are not. diff --git a/skimage/filters/tests/test_gaussian.py b/skimage/filters/tests/test_gaussian.py index 14c95d0e..5130beca 100644 --- a/skimage/filters/tests/test_gaussian.py +++ b/skimage/filters/tests/test_gaussian.py @@ -1,35 +1,35 @@ import numpy as np from numpy.testing import assert_raises -from skimage.filters._gaussian import gaussian_filter +from skimage.filters._gaussian import gaussian from skimage._shared._warnings import expected_warnings def test_negative_sigma(): a = np.zeros((3, 3)) a[1, 1] = 1. - assert_raises(ValueError, gaussian_filter, a, sigma=-1.0) - assert_raises(ValueError, gaussian_filter, a, sigma=[-1.0, 1.0]) - assert_raises(ValueError, gaussian_filter, a, + assert_raises(ValueError, gaussian, a, sigma=-1.0) + assert_raises(ValueError, gaussian, a, sigma=[-1.0, 1.0]) + assert_raises(ValueError, gaussian, a, sigma=np.asarray([-1.0, 1.0])) def test_null_sigma(): a = np.zeros((3, 3)) a[1, 1] = 1. - assert np.all(gaussian_filter(a, 0) == a) + assert np.all(gaussian(a, 0) == a) def test_energy_decrease(): a = np.zeros((3, 3)) a[1, 1] = 1. - gaussian_a = gaussian_filter(a, sigma=1, mode='reflect') + gaussian_a = gaussian(a, sigma=1, mode='reflect') assert gaussian_a.std() < a.std() def test_multichannel(): a = np.zeros((5, 5, 3)) a[1, 1] = np.arange(1, 4) - gaussian_rgb_a = gaussian_filter(a, sigma=1, mode='reflect', + gaussian_rgb_a = gaussian(a, sigma=1, mode='reflect', multichannel=True) # Check that the mean value is conserved in each channel # (color channels are not mixed together) @@ -37,13 +37,13 @@ def test_multichannel(): [gaussian_rgb_a[..., i].mean() for i in range(3)]) # Test multichannel = None with expected_warnings(['multichannel']): - gaussian_rgb_a = gaussian_filter(a, sigma=1, mode='reflect') + gaussian_rgb_a = gaussian(a, sigma=1, mode='reflect') # Check that the mean value is conserved in each channel # (color channels are not mixed together) assert np.allclose([a[..., i].mean() for i in range(3)], [gaussian_rgb_a[..., i].mean() for i in range(3)]) # Iterable sigma - gaussian_rgb_a = gaussian_filter(a, sigma=[1, 2], mode='reflect', + gaussian_rgb_a = gaussian(a, sigma=[1, 2], mode='reflect', multichannel=True) assert np.allclose([a[..., i].mean() for i in range(3)], [gaussian_rgb_a[..., i].mean() for i in range(3)]) diff --git a/skimage/util/tests/test_apply_parallel.py b/skimage/util/tests/test_apply_parallel.py index a43f4338..ec0dba78 100644 --- a/skimage/util/tests/test_apply_parallel.py +++ b/skimage/util/tests/test_apply_parallel.py @@ -3,7 +3,7 @@ from __future__ import absolute_import import numpy as np from numpy.testing import assert_array_almost_equal -from skimage.filters import threshold_adaptive, gaussian_filter +from skimage.filters import threshold_adaptive, gaussian from skimage.util.apply_parallel import apply_parallel @@ -20,9 +20,9 @@ def test_apply_parallel(): assert_array_almost_equal(result1, expected1) def wrapped_gauss(arr): - return gaussian_filter(arr, 1, mode='reflect') + return gaussian(arr, 1, mode='reflect') - expected2 = gaussian_filter(a, 1, mode='reflect') + expected2 = gaussian(a, 1, mode='reflect') result2 = apply_parallel(wrapped_gauss, a, chunks=(6, 6), depth=5) assert_array_almost_equal(result2, expected2) @@ -42,9 +42,9 @@ def test_no_chunks(): def test_apply_parallel_wrap(): def wrapped(arr): - return gaussian_filter(arr, 1, mode='wrap') + return gaussian(arr, 1, mode='wrap') a = np.arange(144).reshape(12, 12).astype(float) - expected = gaussian_filter(a, 1, mode='wrap') + expected = gaussian(a, 1, mode='wrap') result = apply_parallel(wrapped, a, chunks=(6, 6), depth=5, mode='wrap') assert_array_almost_equal(result, expected) @@ -52,9 +52,9 @@ def test_apply_parallel_wrap(): def test_apply_parallel_nearest(): def wrapped(arr): - return gaussian_filter(arr, 1, mode='nearest') + return gaussian(arr, 1, mode='nearest') a = np.arange(144).reshape(12, 12).astype(float) - expected = gaussian_filter(a, 1, mode='nearest') + expected = gaussian(a, 1, mode='nearest') result = apply_parallel(wrapped, a, chunks=(6, 6), depth={0: 5, 1: 5}, mode='nearest')