mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-06 02:00:13 +08:00
@@ -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,16 +50,19 @@ 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
|
||||
>>>
|
||||
>>> 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 +71,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)
|
||||
|
||||
"""
|
||||
@@ -113,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)
|
||||
@@ -139,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
|
||||
--------
|
||||
@@ -149,9 +151,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:
|
||||
@@ -172,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:
|
||||
@@ -219,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:
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
"""
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
----------
|
||||
|
||||
@@ -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:
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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'.
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user