Harmonize all ndimage usage across the library

Only two forms remain in use:

- `from scipy import ndimage as ndi`
- `from scipy.ndimage import function`
This commit is contained in:
Juan Nunez-Iglesias
2015-06-09 15:18:37 +10:00
parent 82a5d0c5d9
commit 0d134987f9
47 changed files with 173 additions and 185 deletions
+2 -2
View File
@@ -3,7 +3,7 @@
#cython: nonecheck=False
#cython: wraparound=False
import numpy as np
import scipy
from scipy import ndimage as ndi
cimport cython
cimport numpy as cnp
@@ -47,7 +47,7 @@ def _felzenszwalb_grey(image, double scale=1, sigma=0.8,
# rescale scale to behave like in reference implementation
scale = float(scale) / 255.
image = scipy.ndimage.gaussian_filter(image, sigma=sigma)
image = ndi.gaussian_filter(image, sigma=sigma)
# compute edge weights in 8 connectivity:
right_cost = np.abs((image[1:, :] - image[:-1, :]))
+2 -2
View File
@@ -3,7 +3,7 @@
#cython: nonecheck=False
#cython: wraparound=False
import numpy as np
from scipy import ndimage
from scipy import ndimage as ndi
from itertools import product
cimport numpy as cnp
@@ -69,7 +69,7 @@ def quickshift(image, ratio=1., float kernel_size=5, max_dist=10,
ValueError("Only RGB images can be converted to Lab space.")
image = rgb2lab(image)
image = ndimage.gaussian_filter(img_as_float(image), [sigma, sigma, 0])
image = ndi.gaussian_filter(img_as_float(image), [sigma, sigma, 0])
cdef cnp.ndarray[dtype=cnp.float_t, ndim=3, mode="c"] image_c \
= np.ascontiguousarray(image) * ratio
+6 -6
View File
@@ -1,7 +1,7 @@
from __future__ import division
import numpy as np
from scipy import ndimage as nd
from scipy import ndimage as ndi
from ..morphology import dilation, erosion, square
from ..util import img_as_float, view_as_windows, pad
from ..color import gray2rgb
@@ -146,7 +146,7 @@ def find_boundaries(label_img, connectivity=1, mode='thick', background=0):
[0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
"""
ndim = label_img.ndim
selem = nd.generate_binary_structure(ndim, connectivity)
selem = ndi.generate_binary_structure(ndim, connectivity)
if mode != 'subpixel':
boundaries = dilation(label_img, selem) != erosion(label_img, selem)
if mode == 'inner':
@@ -155,7 +155,7 @@ def find_boundaries(label_img, connectivity=1, mode='thick', background=0):
elif mode == 'outer':
max_label = np.iinfo(label_img.dtype).max
background_image = (label_img == background)
selem = nd.generate_binary_structure(ndim, ndim)
selem = ndi.generate_binary_structure(ndim, ndim)
inverted_background = np.array(label_img, copy=True)
inverted_background[background_image] = max_label
adjacent_objects = ((dilation(label_img, selem) !=
@@ -205,10 +205,10 @@ def mark_boundaries(image, label_img, color=(1, 1, 0),
if mode == 'subpixel':
# Here, we want to interpose an extra line of pixels between
# each original line - except for the last axis which holds
# the RGB information. ``nd.zoom`` then performs the (cubic)
# the RGB information. ``ndi.zoom`` then performs the (cubic)
# interpolation, filling in the values of the interposed pixels
marked = nd.zoom(marked, [2 - 1/s for s in marked.shape[:-1]] + [1],
mode='reflect')
marked = ndi.zoom(marked, [2 - 1/s for s in marked.shape[:-1]] + [1],
mode='reflect')
boundaries = find_boundaries(label_img, mode=mode,
background=background_label)
if outline_color is not None:
@@ -10,7 +10,7 @@ significantly the performance.
import warnings
import numpy as np
from scipy import sparse, ndimage
from scipy import sparse, ndimage as ndi
# executive summary for next code block: try to import umfpack from
# scipy, but make sure not to raise a fuss if it fails since it's only
@@ -417,7 +417,7 @@ def random_walker(data, labels, beta=130, mode='bf', tol=1.e-3, copy=True,
# If the array has pruned zones, be sure that no isolated pixels
# exist between pruned zones (they could not be determined)
if np.any(labels < 0):
filled = ndimage.binary_propagation(labels > 0, mask=labels >= 0)
filled = ndi.binary_propagation(labels > 0, mask=labels >= 0)
labels[np.logical_and(np.logical_not(filled), labels == 0)] = -1
del filled
labels = np.atleast_3d(labels)
+2 -2
View File
@@ -2,7 +2,7 @@
import collections as coll
import numpy as np
from scipy import ndimage
from scipy import ndimage as ndi
import warnings
from ..util import img_as_float, regular_grid
@@ -139,7 +139,7 @@ def slic(image, n_segments=100, compactness=10., max_iter=10, sigma=0,
if (sigma > 0).any():
# add zero smoothing for multichannel dimension
sigma = list(sigma) + [0]
image = ndimage.gaussian_filter(image, sigma)
image = ndi.gaussian_filter(image, sigma)
if multichannel and (convert2lab or convert2lab is None):
if image.shape[-1] != 3 and convert2lab: