From 2614853a923a9e10b9a6c7b74ab50b269319b8d4 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 11 Sep 2012 23:33:15 -0400 Subject: [PATCH 1/9] DOC: suppress plot display in doctests Plot display interrupts the doctest run. --- skimage/transform/finite_radon_transform.py | 2 +- skimage/transform/hough_transform.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/transform/finite_radon_transform.py b/skimage/transform/finite_radon_transform.py index 13007dce..fa84c5e3 100644 --- a/skimage/transform/finite_radon_transform.py +++ b/skimage/transform/finite_radon_transform.py @@ -52,7 +52,7 @@ def frt2(a): >>> plt.imshow(f, interpolation='nearest', cmap=plt.cm.gray) >>> plt.xlabel('Angle') >>> plt.ylabel('Translation') - >>> plt.show() + >>> # plt.show() References ---------- diff --git a/skimage/transform/hough_transform.py b/skimage/transform/hough_transform.py index 5b36b103..3c3a35de 100644 --- a/skimage/transform/hough_transform.py +++ b/skimage/transform/hough_transform.py @@ -137,7 +137,7 @@ def hough(img, theta=None): >>> plt.imshow(out, cmap=plt.cm.bone) >>> plt.xlabel('Angle (degree)') >>> plt.ylabel('Distance %d (pixel)' % d[0]) - >>> plt.show() + >>> # plt.show() .. plot:: hough_tf.py From 24f3b7d26008c6954b71bfc65c2d41a970e27c75 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 11 Sep 2012 23:35:09 -0400 Subject: [PATCH 2/9] DOC: Fix block-formatting in doctest --- skimage/transform/hough_transform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/transform/hough_transform.py b/skimage/transform/hough_transform.py index 3c3a35de..0e1fb9bf 100644 --- a/skimage/transform/hough_transform.py +++ b/skimage/transform/hough_transform.py @@ -124,7 +124,7 @@ def hough(img, theta=None): >>> img[:, 65] = 1 >>> img[35:45, 35:50] = 1 >>> for i in range(90): - >>> img[i, i] = 1 + ... img[i, i] = 1 >>> img += np.random.random(img.shape) > 0.95 Apply the Hough transform: From 0504392fd5f730b0fcdcb37660cff89829b4870e Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 11 Sep 2012 23:36:12 -0400 Subject: [PATCH 3/9] DOC: Fix doctests in io collection module --- skimage/io/collection.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/skimage/io/collection.py b/skimage/io/collection.py index 37eacfff..d420b58d 100644 --- a/skimage/io/collection.py +++ b/skimage/io/collection.py @@ -56,9 +56,10 @@ def alphanumeric_key(s): -------- >>> alphanumeric_key('z23a') ['z', 23, 'a'] - >>> filenames = ['f9.10.png', 'f9.9.png', 'f10.10.png', 'f10.9.png'] + >>> filenames = ['f9.10.png', 'e10.png', 'f9.9.png', 'f10.10.png', + ... 'f10.9.png'] >>> sorted(filenames) - ['f10.10.png', 'f10.9.png', 'f9.10.png', 'f9.9.png', 'e10.png'] + ['e10.png', 'f10.10.png', 'f10.9.png', 'f9.10.png', 'f9.9.png'] >>> sorted(filenames, key=alphanumeric_key) ['e10.png', 'f9.9.png', 'f9.10.png', 'f10.9.png', 'f10.10.png'] """ @@ -284,7 +285,7 @@ class ImageCollection(object): >>> len(coll) 2 >>> coll[0].shape - (128, 128, 3) + (512, 512, 3) >>> ic = io.ImageCollection('/tmp/work/*.png:/tmp/other/*.jpg') From 7134a2609f72f34177919de9023630d3bf34aaa7 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 11 Sep 2012 23:37:07 -0400 Subject: [PATCH 4/9] DOC: Fix array formatting in doctest --- .../random_walker_segmentation.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/skimage/segmentation/random_walker_segmentation.py b/skimage/segmentation/random_walker_segmentation.py index 52bf4425..7597d5b6 100644 --- a/skimage/segmentation/random_walker_segmentation.py +++ b/skimage/segmentation/random_walker_segmentation.py @@ -324,16 +324,16 @@ def random_walker(data, labels, beta=130, mode='bf', tol=1.e-3, copy=True, >>> b[3,3] = 1 #Marker for first phase >>> b[6,6] = 2 #Marker for second phase >>> random_walker(a, b) - array([[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], - [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], - [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], - [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], - [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], - [ 1., 1., 1., 1., 1., 2., 2., 2., 1., 1.], - [ 1., 1., 1., 1., 1., 2., 2., 2., 1., 1.], - [ 1., 1., 1., 1., 1., 2., 2., 2., 1., 1.], - [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], - [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]]) + array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 2, 2, 2, 1, 1], + [1, 1, 1, 1, 1, 2, 2, 2, 1, 1], + [1, 1, 1, 1, 1, 2, 2, 2, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=int32) """ # Parse input data From fcf2a9bc970a96d698c8ada44c98de81520dc411 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 11 Sep 2012 23:38:00 -0400 Subject: [PATCH 5/9] DOC: Fix doctests in viewer subpackage The doctests in the viewer subpackage weren't originally written as proper doctests. --- skimage/viewer/plugins/base.py | 26 +++++++++++++------------- skimage/viewer/viewers/core.py | 5 +++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/skimage/viewer/plugins/base.py b/skimage/viewer/plugins/base.py index 074e18d4..198bac6a 100644 --- a/skimage/viewer/plugins/base.py +++ b/skimage/viewer/plugins/base.py @@ -54,17 +54,17 @@ class Plugin(QDialog): Examples -------- - >>> def my_func(image, arg1, arg2, optional_arg=0): - >>> ... + >>> from skimage.viewer import ImageViewer + >>> from skimage.viewer.widgets import Slider + >>> from skimage import data >>> + >>> plugin = Plugin(image_filter=lambda img, threshold: img > threshold) + >>> plugin += Slider('threshold', 0, 255) + >>> + >>> image = data.coins() >>> viewer = ImageViewer(image) - >>> - >>> plugin = Plugin(image_filter=my_func) - >>> plugin += Widget('arg1', ..., ptype='arg') - >>> plugin += Widget('arg2', ..., ptype='arg') - >>> plugin += Widget('optional_arg', ..., ptype='kwarg') - >>> - >>> viewer.show() + >>> viewer += plugin + >>> # viewer.show() The plugin will automatically delegate parameters to `image_filter` based on its parameter type, i.e., `ptype` (widgets for required arguments must @@ -108,9 +108,9 @@ class Plugin(QDialog): """Attach the plugin to an ImageViewer. Note that the ImageViewer will automatically call this method when the - plugin is added to the ImageViewer. For example: + plugin is added to the ImageViewer. For example:: - >>> viewer += Plugin(...) + viewer += Plugin(...) Also note that `attach` automatically calls the filter function so that the image matches the filtered value specified by attached widgets. @@ -131,9 +131,9 @@ class Plugin(QDialog): def add_widget(self, widget): """Add widget to plugin. - Alternatively, Plugin's `__add__` method is overloaded to add widgets: + Alternatively, Plugin's `__add__` method is overloaded to add widgets:: - >>> plugin += Widget(...) + plugin += Widget(...) Widgets can adjust required or optional arguments of filter function or parameters for the plugin. This is specified by the Widget's `ptype'. diff --git a/skimage/viewer/viewers/core.py b/skimage/viewer/viewers/core.py index 490ff92c..7aadb571 100644 --- a/skimage/viewer/viewers/core.py +++ b/skimage/viewer/viewers/core.py @@ -49,9 +49,10 @@ class ImageViewer(QMainWindow): Examples -------- + >>> from skimage import data + >>> image = data.coins() >>> viewer = ImageViewer(image) - >>> viewer += SomePlugin() - >>> viewer.show() + >>> # viewer.show() """ def __init__(self, image): From a58ce5b5719e89db676ae6070a45dff961871195 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 11 Sep 2012 23:39:08 -0400 Subject: [PATCH 6/9] DOC: Add missing import in doctest --- skimage/graph/mcp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skimage/graph/mcp.py b/skimage/graph/mcp.py index 28843cbf..27b7062f 100644 --- a/skimage/graph/mcp.py +++ b/skimage/graph/mcp.py @@ -39,7 +39,9 @@ def route_through_array(array, start, end, fully_connected=True, Examples -------- + >>> import numpy as np >>> from skimage.graph import route_through_array + >>> >>> image = np.array([[1, 3], [10, 12]]) >>> image array([[ 1, 3], From 7a9cb807d11754661c98baa3c4c9ef876b0dff99 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 11 Sep 2012 23:42:22 -0400 Subject: [PATCH 7/9] DOC: Fix doctests in lpi_filter --- skimage/filter/lpi_filter.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/skimage/filter/lpi_filter.py b/skimage/filter/lpi_filter.py index 60eb1d63..d023185f 100644 --- a/skimage/filter/lpi_filter.py +++ b/skimage/filter/lpi_filter.py @@ -58,8 +58,12 @@ class LPIFilter2D(object): In other words, example would be called like this: + >>> def impulse_response(r, c, **filter_params): + ... pass + >>> >>> r = [0,0,0,1,1,1,2,2,2] >>> c = [0,1,2,0,1,2,0,1,2] + >>> filter_params = {'kw1': 1, 'kw2': 2, 'kw3': 3} >>> impulse_response(r, c, **filter_params) Examples @@ -68,8 +72,7 @@ class LPIFilter2D(object): Gaussian filter: >>> def filt_func(r, c): - return np.exp(-np.hypot(r, c)/1) - + ... return np.exp(-np.hypot(r, c)/1) >>> filter = LPIFilter2D(filt_func) """ @@ -149,9 +152,10 @@ def forward(data, impulse_response=None, filter_params={}, Gaussian filter: >>> def filt_func(r, c): - return np.exp(-np.hypot(r, c)/1) - - >>> forward(data, filt_func) + ... return np.exp(-np.hypot(r, c)/1) + >>> + >>> from skimage import data + >>> filtered = forward(data.coins(), filt_func) """ if predefined_filter is None: From ae429011cf477a29e5818160075f05fa77e7ec17 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 11 Sep 2012 23:46:26 -0400 Subject: [PATCH 8/9] DOC: rewrap docstring lines and remove unused import --- skimage/filter/lpi_filter.py | 40 ++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/skimage/filter/lpi_filter.py b/skimage/filter/lpi_filter.py index d023185f..3826f5e7 100644 --- a/skimage/filter/lpi_filter.py +++ b/skimage/filter/lpi_filter.py @@ -7,7 +7,7 @@ __all__ = ['inverse', 'wiener', 'LPIFilter2D'] __docformat__ = 'restructuredtext en' import numpy as np -from scipy.fftpack import fftshift, ifftshift +from scipy.fftpack import ifftshift eps = np.finfo(float).eps @@ -50,13 +50,12 @@ class LPIFilter2D(object): Parameters ---------- impulse_response : callable `f(r, c, **filter_params)` - Function that yields the impulse response. `r` and - `c` are 1-dimensional vectors that represent row and - column positions, in other words coordinates are - (r[0],c[0]),(r[0],c[1]) etc. `**filter_params` are - passed through. + Function that yields the impulse response. `r` and `c` are + 1-dimensional vectors that represent row and column positions, in + other words coordinates are (r[0],c[0]),(r[0],c[1]) etc. + `**filter_params` are passed through. - In other words, example would be called like this: + In other words, `impulse_response` would be called like this: >>> def impulse_response(r, c, **filter_params): ... pass @@ -116,8 +115,9 @@ class LPIFilter2D(object): def __call__(self, data): """Apply the filter to the given data. - *Parameters*: - data : (M,N) ndarray + Parameters + ---------- + data : (M,N) ndarray """ F, G = self._prepare(data) @@ -142,9 +142,8 @@ def forward(data, impulse_response=None, filter_params={}, Other Parameters ---------------- predefined_filter : LPIFilter2D - If you need to apply the same filter multiple times over - different images, construct the LPIFilter2D and specify - it here. + If you need to apply the same filter multiple times over different + images, construct the LPIFilter2D and specify it here. Examples -------- @@ -176,17 +175,15 @@ def inverse(data, impulse_response=None, filter_params={}, max_gain=2, filter_params : dict Additional keyword parameters to the impulse_response function. max_gain : float - Limit the filter gain. Often, the filter contains - zeros, which would cause the inverse filter to have - infinite gain. High gain causes amplification of - artefacts, so a conservative limit is recommended. + Limit the filter gain. Often, the filter contains zeros, which would + cause the inverse filter to have infinite gain. High gain causes + amplification of artefacts, so a conservative limit is recommended. Other Parameters ---------------- predefined_filter : LPIFilter2D - If you need to apply the same filter multiple times over - different images, construct the LPIFilter2D and specify - it here. + If you need to apply the same filter multiple times over different + images, construct the LPIFilter2D and specify it here. """ if predefined_filter is None: @@ -223,9 +220,8 @@ def wiener(data, impulse_response=None, filter_params={}, K=0.25, Other Parameters ---------------- predefined_filter : LPIFilter2D - If you need to apply the same filter multiple times over - different images, construct the LPIFilter2D and specify - it here. + If you need to apply the same filter multiple times over different + images, construct the LPIFilter2D and specify it here. """ if predefined_filter is None: From 538ce329a5db2c2a425422b275a7c5590e94b863 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 11 Sep 2012 23:47:18 -0400 Subject: [PATCH 9/9] DOC: fix numpy dtype print out. This fix may be very dependent on numpy version since print out has change over time. --- skimage/morphology/grey.py | 12 ++++++------ skimage/morphology/watershed.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index dc34d3d6..a7959bb6 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -57,7 +57,7 @@ def erosion(image, selem, out=None, shift_x=False, shift_y=False): [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], - [0, 0, 0, 0, 0]], dtype='uint8') + [0, 0, 0, 0, 0]], dtype=uint8) """ @@ -109,7 +109,7 @@ def dilation(image, selem, out=None, shift_x=False, shift_y=False): [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], - [0, 0, 0, 0, 0]], dtype='uint8') + [0, 0, 0, 0, 0]], dtype=uint8) """ @@ -158,7 +158,7 @@ def opening(image, selem, out=None): [1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [1, 1, 0, 1, 1], - [0, 0, 0, 0, 0]], dtype='uint8') + [0, 0, 0, 0, 0]], dtype=uint8) """ @@ -208,7 +208,7 @@ def closing(image, selem, out=None): [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], - [0, 0, 0, 0, 0]], dtype='uint8') + [0, 0, 0, 0, 0]], dtype=uint8) """ @@ -257,7 +257,7 @@ def white_tophat(image, selem, out=None): [0, 0, 1, 0, 0], [0, 1, 5, 1, 0], [0, 0, 1, 0, 0], - [0, 0, 0, 0, 0]], dtype='uint8') + [0, 0, 0, 0, 0]], dtype=uint8) """ if image is out: @@ -306,7 +306,7 @@ def black_tophat(image, selem, out=None): [0, 0, 1, 0, 0], [0, 1, 5, 1, 0], [0, 0, 1, 0, 0], - [0, 0, 0, 0, 0]], dtype='uint8') + [0, 0, 0, 0, 0]], dtype=uint8) """ diff --git a/skimage/morphology/watershed.py b/skimage/morphology/watershed.py index c0b1b34b..8a08fafc 100644 --- a/skimage/morphology/watershed.py +++ b/skimage/morphology/watershed.py @@ -261,7 +261,7 @@ def is_local_maximum(image, labels=None, footprint=None): array([[ True, False, False, False], [ True, False, True, False], [ True, False, False, False], - [ True, True, False, True]], dtype='bool') + [ True, True, False, True]], dtype=bool) >>> image = np.arange(16).reshape((4, 4)) >>> labels = np.array([[1, 2], [3, 4]]) >>> labels = np.repeat(np.repeat(labels, 2, axis=0), 2, axis=1) @@ -279,7 +279,7 @@ def is_local_maximum(image, labels=None, footprint=None): array([[False, False, False, False], [False, True, False, True], [False, False, False, False], - [False, True, False, True]], dtype='bool') + [False, True, False, True]], dtype=bool) """ if labels is None: labels = np.ones(image.shape, dtype=np.uint8)