Merge pull request #752 from sciunto/pep

Pep8 and other misc cosmetics.
This commit is contained in:
Johannes Schönberger
2013-10-02 09:30:01 -07:00
11 changed files with 35 additions and 42 deletions
-1
View File
@@ -7,7 +7,6 @@ Image entropy is a quantity which is used to describe the amount of information
coded in an image.
"""
import numpy as np
import matplotlib.pyplot as plt
from skimage import data
+4 -4
View File
@@ -249,8 +249,8 @@ def maximum(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
Note
----
* the lower algorithm complexity makes the rank.maximum() more efficient for
larger images and structuring elements
* the lower algorithm complexity makes the rank.maximum() more efficient
for larger images and structuring elements
"""
@@ -299,7 +299,7 @@ def mean(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
def subtract_mean(image, selem, out=None, mask=None, shift_x=False,
shift_y=False):
shift_y=False):
"""Return image subtracted from its local mean.
Parameters
@@ -439,7 +439,7 @@ def modal(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
def enhance_contrast(image, selem, out=None, mask=None, shift_x=False,
shift_y=False):
shift_y=False):
"""Enhance an image replacing each pixel by the local maximum if pixel
greylevel is closest to maximimum than local minimum OR local minimum
otherwise.
+11 -11
View File
@@ -1,4 +1,4 @@
__all__ = ['threshold_adaptive', 'threshold_otsu', 'threshold_yen']
__all__ = ['threshold_adaptive', 'threshold_otsu', 'threshold_yen']
import numpy as np
import scipy.ndimage
@@ -65,7 +65,7 @@ def threshold_adaptive(image, block_size, method='gaussian', offset=0,
thresh_image = np.zeros(image.shape, 'double')
if method == 'generic':
scipy.ndimage.generic_filter(image, param, block_size,
output=thresh_image, mode=mode)
output=thresh_image, mode=mode)
elif method == 'gaussian':
if param is None:
# automatically determine sigma which covers > 99% of distribution
@@ -73,17 +73,17 @@ def threshold_adaptive(image, block_size, method='gaussian', offset=0,
else:
sigma = param
scipy.ndimage.gaussian_filter(image, sigma, output=thresh_image,
mode=mode)
mode=mode)
elif method == 'mean':
mask = 1. / block_size * np.ones((block_size,))
# separation of filters to speedup convolution
scipy.ndimage.convolve1d(image, mask, axis=0, output=thresh_image,
mode=mode)
mode=mode)
scipy.ndimage.convolve1d(thresh_image, mask, axis=1,
output=thresh_image, mode=mode)
output=thresh_image, mode=mode)
elif method == 'median':
scipy.ndimage.median_filter(image, block_size, output=thresh_image,
mode=mode)
mode=mode)
return image > (thresh_image - offset)
@@ -146,7 +146,7 @@ def threshold_yen(image, nbins=256):
nbins : int, optional
Number of bins used to calculate histogram. This value is ignored for
integer arrays.
Returns
-------
threshold : float
@@ -155,11 +155,11 @@ def threshold_yen(image, nbins=256):
References
----------
.. [1] Yen J.C., Chang F.J., and Chang S. (1995) "A New Criterion
for Automatic Multilevel Thresholding" IEEE Trans. on Image
.. [1] Yen J.C., Chang F.J., and Chang S. (1995) "A New Criterion
for Automatic Multilevel Thresholding" IEEE Trans. on Image
Processing, 4(3): 370-378
.. [2] Sezgin M. and Sankur B. (2004) "Survey over Image Thresholding
Techniques and Quantitative Performance Evaluation" Journal of
.. [2] Sezgin M. and Sankur B. (2004) "Survey over Image Thresholding
Techniques and Quantitative Performance Evaluation" Journal of
Electronic Imaging, 13(1): 146-165,
http://www.busim.ee.boun.edu.tr/~sankur/SankurFolder/Threshold_survey.pdf
.. [3] ImageJ AutoThresholder code, http://fiji.sc/wiki/index.php/Auto_Threshold
+1 -1
View File
@@ -256,7 +256,7 @@ class Video(object):
Backend to use.
"""
def __init__(self, source=None, size=None, sync=False, backend=None):
if backend == None:
if backend is None:
# select backend that is available
if gstreamer_available:
self.video = GstVideo(source, size, sync)
+1 -1
View File
@@ -116,7 +116,7 @@ def find_contours(array, level,
raise ValueError('Parameters "fully_connected" and'
' "positive_orientation" must be either "high" or "low".')
point_list = _find_contours.iterate_and_store(array, level,
fully_connected == 'high')
fully_connected == 'high')
contours = _assemble_contours(_take_2(point_list))
if positive_orientation == 'high':
contours = [c[::-1] for c in contours]
+1
View File
@@ -212,6 +212,7 @@ def medial_axis(image, mask=None, return_distance=False):
Examples
--------
>>> from skimage import morphology
>>> square = np.zeros((7, 7), dtype=np.uint8)
>>> square[1:-1, 2:-2] = 1
>>> square
+1 -1
View File
@@ -133,7 +133,7 @@ def reconstruction(seed, mask, method='dilation', selem=None, offset=None):
else:
selem = selem.copy()
if offset == None:
if offset is None:
if not all([d % 2 == 1 for d in selem.shape]):
ValueError("Footprint dimensions must all be odd")
offset = np.array([d // 2 for d in selem.shape])
+9 -9
View File
@@ -172,10 +172,10 @@ def octahedron(radius, dtype=np.uint8):
"""
# note that in contrast to diamond(), this method allows non-integer radii
n = 2 * radius + 1
Z, Y, X = np.mgrid[ -radius:radius:n*1j,
-radius:radius:n*1j,
-radius:radius:n*1j]
s = np.abs(X) + np.abs(Y) + np.abs(Z)
Z, Y, X = np.mgrid[-radius:radius:n*1j,
-radius:radius:n*1j,
-radius:radius:n*1j]
s = np.abs(X) + np.abs(Y) + np.abs(Z)
return np.array(s <= radius, dtype=dtype)
@@ -203,9 +203,9 @@ def ball(radius, dtype=np.uint8):
are 1 and 0 otherwise.
"""
n = 2 * radius + 1
Z, Y, X = np.mgrid[ -radius:radius:n*1j,
-radius:radius:n*1j,
-radius:radius:n*1j]
Z, Y, X = np.mgrid[-radius:radius:n*1j,
-radius:radius:n*1j,
-radius:radius:n*1j]
s = X**2 + Y**2 + Z**2
return np.array(s <= radius * radius, dtype=dtype)
@@ -240,9 +240,9 @@ def octagon(m, n, dtype=np.uint8):
selem = np.zeros((m + 2*n, m + 2*n))
selem[0, n] = 1
selem[n, 0] = 1
selem[0, m + n -1] = 1
selem[0, m + n - 1] = 1
selem[m + n - 1, 0] = 1
selem[-1, n] = 1
selem[-1, n] = 1
selem[n, -1] = 1
selem[-1, m + n - 1] = 1
selem[m + n - 1, -1] = 1
+4 -4
View File
@@ -124,13 +124,13 @@ def watershed(image, markers, connectivity=None, offset=None, mask=None):
separate overlapping spheres.
"""
if connectivity == None:
if connectivity is None:
c_connectivity = scipy.ndimage.generate_binary_structure(image.ndim, 1)
else:
c_connectivity = np.array(connectivity, bool)
if c_connectivity.ndim != image.ndim:
raise ValueError("Connectivity dimension must be same as image")
if offset == None:
if offset is None:
if any([x % 2 == 0 for x in c_connectivity.shape]):
raise ValueError("Connectivity array must have an unambiguous "
"center")
@@ -162,7 +162,7 @@ def watershed(image, markers, connectivity=None, offset=None, mask=None):
"as image (ndim=%d)" % (c_markers.ndim, c_image.ndim))
if c_markers.shape != c_image.shape:
raise ValueError("image and markers must have the same shape")
if mask != None:
if mask is not None:
c_mask = np.ascontiguousarray(mask, dtype=bool)
if c_mask.ndim != c_markers.ndim:
raise ValueError("mask must have same # of dimensions as image")
@@ -398,7 +398,7 @@ def _slow_watershed(image, markers, connectivity=8, mask=None):
continue
if labels[x, y]:
continue
if mask != None and not mask[x, y]:
if mask is not None and not mask[x, y]:
continue
# label the pixel
labels[x, y] = pix_label
-2
View File
@@ -20,7 +20,6 @@ def join_segmentations(s1, s2):
Examples
--------
>>> import numpy as np
>>> from skimage.segmentation import join_segmentations
>>> s1 = np.array([[0, 0, 1, 1],
... [0, 2, 1, 1],
@@ -78,7 +77,6 @@ def relabel_from_one(label_field):
Examples
--------
>>> import numpy as np
>>> from skimage.segmentation import relabel_from_one
>>> label_field = array([1, 1, 5, 5, 8, 99, 42])
>>> relab, fw, inv = relabel_from_one(label_field)
+3 -8
View File
@@ -1,12 +1,8 @@
import numpy as np
try:
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
LABELS_CMAP = mcolors.ListedColormap(['white', 'red', 'dodgerblue', 'gold',
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
LABELS_CMAP = mcolors.ListedColormap(['white', 'red', 'dodgerblue', 'gold',
'greenyellow', 'blueviolet'])
except ImportError:
print("Could not import matplotlib -- skimage.viewer not available.")
from skimage.viewer.canvastools.base import CanvasToolBase
@@ -192,7 +188,6 @@ class CenteredWindow(object):
if __name__ == '__main__':
np.testing.rundocs()
import matplotlib.pyplot as plt
from skimage import data
image = data.camera()