本文整理汇总了Python中skimage._shared.utils.assert_nD函数的典型用法代码示例。如果您正苦于以下问题:Python assert_nD函数的具体用法?Python assert_nD怎么用?Python assert_nD使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_nD函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: roberts_negative_diagonal
def roberts_negative_diagonal(image, mask=None):
"""Find the cross edges of an image using the Roberts' Cross operator.
The kernel is applied to the input image to produce separate measurements
of the gradient component one orientation.
Parameters
----------
image : 2-D array
Image to process.
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Robert's edge map.
Notes
-----
We use the following kernel and return the absolute value of the
result at each point::
0 1
-1 0
"""
assert_nD(image, 2)
image = img_as_float(image)
result = np.abs(convolve(image, ROBERTS_ND_WEIGHTS))
return _mask_filter_result(result, mask)
开发者ID:lotteanna,项目名称:scikit-image,代码行数:33,代码来源:edges.py
示例2: prewitt_v
def prewitt_v(image, mask=None):
"""Find the vertical edges of an image using the Prewitt transform.
Parameters
----------
image : 2-D array
Image to process.
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Prewitt edge map.
Notes
-----
We use the following kernel::
1 0 -1
1 0 -1
1 0 -1
"""
assert_nD(image, 2)
image = img_as_float(image)
result = convolve(image, VPREWITT_WEIGHTS)
return _mask_filter_result(result, mask)
开发者ID:borevitzlab,项目名称:scikit-image,代码行数:30,代码来源:edges.py
示例3: sobel
def sobel(image, mask=None):
"""Find the edge magnitude using the Sobel transform.
Parameters
----------
image : 2-D array
Image to process.
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Sobel edge map.
Notes
-----
Take the square root of the sum of the squares of the horizontal and
vertical Sobels to get a magnitude that's somewhat insensitive to
direction.
Note that ``scipy.ndimage.sobel`` returns a directional Sobel which
has to be further processed to perform edge detection.
"""
assert_nD(image, 2)
out = np.sqrt(hsobel(image, mask)**2 + vsobel(image, mask)**2)
out /= np.sqrt(2)
return out
开发者ID:lotteanna,项目名称:scikit-image,代码行数:30,代码来源:edges.py
示例4: scharr_v
def scharr_v(image, mask=None):
"""Find the vertical edges of an image using the Scharr transform.
Parameters
----------
image : 2-D array
Image to process
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Scharr edge map.
Notes
-----
We use the following kernel::
3 0 -3
10 0 -10
3 0 -3
References
----------
.. [1] D. Kroon, 2009, Short Paper University Twente, Numerical
Optimization of Kernel Based Image Derivatives.
"""
assert_nD(image, 2)
image = img_as_float(image)
result = convolve(image, VSCHARR_WEIGHTS)
return _mask_filter_result(result, mask)
开发者ID:borevitzlab,项目名称:scikit-image,代码行数:35,代码来源:edges.py
示例5: hsobel
def hsobel(image, mask=None):
"""Find the horizontal edges of an image using the Sobel transform.
Parameters
----------
image : 2-D array
Image to process.
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Sobel edge map.
Notes
-----
We use the following kernel and return the absolute value of the
result at each point::
1 2 1
0 0 0
-1 -2 -1
"""
assert_nD(image, 2)
image = img_as_float(image)
result = np.abs(convolve(image, HSOBEL_WEIGHTS))
return _mask_filter_result(result, mask)
开发者ID:lotteanna,项目名称:scikit-image,代码行数:31,代码来源:edges.py
示例6: forward
def forward(data, impulse_response=None, filter_params={},
predefined_filter=None):
"""Apply the given filter to data.
Parameters
----------
data : (M,N) ndarray
Input data.
impulse_response : callable `f(r, c, **filter_params)`
Impulse response of the filter. See LPIFilter2D.__init__.
filter_params : dict
Additional keyword parameters to the impulse_response function.
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.
Examples
--------
Gaussian filter:
>>> def filt_func(r, c):
... return np.exp(-np.hypot(r, c)/1)
>>>
>>> from skimage import data
>>> filtered = forward(data.coins(), filt_func)
"""
assert_nD(data, 2, 'data')
if predefined_filter is None:
predefined_filter = LPIFilter2D(impulse_response, **filter_params)
return predefined_filter(data)
开发者ID:Rapternmn,项目名称:scikit-image,代码行数:35,代码来源:lpi_filter.py
示例7: roberts
def roberts(image, mask=None):
"""Find the edge magnitude using Roberts' cross operator.
Parameters
----------
image : 2-D array
Image to process.
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Roberts' Cross edge map.
See also
--------
sobel, scharr, prewitt, feature.canny
Examples
--------
>>> from skimage import data
>>> camera = data.camera()
>>> from skimage import filters
>>> edges = filters.roberts(camera)
"""
assert_nD(image, 2)
out = np.sqrt(roberts_pos_diag(image, mask)**2 +
roberts_neg_diag(image, mask)**2)
out /= np.sqrt(2)
return out
开发者ID:borevitzlab,项目名称:scikit-image,代码行数:34,代码来源:edges.py
示例8: prewitt
def prewitt(image, mask=None):
"""Find the edge magnitude using the Prewitt transform.
Parameters
----------
image : 2-D array
Image to process.
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Prewitt edge map.
Notes
-----
Return the square root of the sum of squares of the horizontal
and vertical Prewitt transforms.
"""
assert_nD(image, 2)
out = np.sqrt(hprewitt(image, mask)**2 + vprewitt(image, mask)**2)
out /= np.sqrt(2)
return out
开发者ID:lotteanna,项目名称:scikit-image,代码行数:26,代码来源:edges.py
示例9: local_binary_pattern
def local_binary_pattern(image, P, R, method='default'):
"""Gray scale and rotation invariant LBP (Local Binary Patterns).
LBP is an invariant descriptor that can be used for texture classification.
Parameters
----------
image : (N, M) array
Graylevel image.
P : int
Number of circularly symmetric neighbour set points (quantization of
the angular space).
R : float
Radius of circle (spatial resolution of the operator).
method : {'default', 'ror', 'uniform', 'var'}
Method to determine the pattern.
* 'default': original local binary pattern which is gray scale but not
rotation invariant.
* 'ror': extension of default implementation which is gray scale and
rotation invariant.
* 'uniform': improved rotation invariance with uniform patterns and
finer quantization of the angular space which is gray scale and
rotation invariant.
* 'nri_uniform': non rotation-invariant uniform patterns variant
which is only gray scale invariant [2].
* 'var': rotation invariant variance measures of the contrast of local
image texture which is rotation but not gray scale invariant.
Returns
-------
output : (N, M) array
LBP image.
References
----------
.. [1] Multiresolution Gray-Scale and Rotation Invariant Texture
Classification with Local Binary Patterns.
Timo Ojala, Matti Pietikainen, Topi Maenpaa.
http://www.rafbis.it/biplab15/images/stories/docenti/Danielriccio/Articoliriferimento/LBP.pdf, 2002.
.. [2] Face recognition with local binary patterns.
Timo Ahonen, Abdenour Hadid, Matti Pietikainen,
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.214.6851,
2004.
"""
assert_nD(image, 2)
methods = {
'default': ord('D'),
'ror': ord('R'),
'uniform': ord('U'),
'nri_uniform': ord('N'),
'var': ord('V')
}
image = np.ascontiguousarray(image, dtype=np.double)
output = _local_binary_pattern(image, P, R, methods[method.lower()])
return output
开发者ID:JeanKossaifi,项目名称:scikit-image,代码行数:57,代码来源:texture.py
示例10: extract
def extract(self, image, keypoints):
"""Extract BRIEF binary descriptors for given keypoints in image.
Parameters
----------
image : 2D array
Input image.
keypoints : (N, 2) array
Keypoint coordinates as ``(row, col)``.
"""
assert_nD(image, 2)
np.random.seed(self.sample_seed)
image = _prepare_grayscale_input_2D(image)
# Gaussian low-pass filtering to alleviate noise sensitivity
image = np.ascontiguousarray(gaussian_filter(image, self.sigma))
# Sampling pairs of decision pixels in patch_size x patch_size window
desc_size = self.descriptor_size
patch_size = self.patch_size
if self.mode == 'normal':
samples = (patch_size / 5.0) * np.random.randn(desc_size * 8)
samples = np.array(samples, dtype=np.int32)
samples = samples[(samples < (patch_size // 2))
& (samples > - (patch_size - 2) // 2)]
pos1 = samples[:desc_size * 2].reshape(desc_size, 2)
pos2 = samples[desc_size * 2:desc_size * 4].reshape(desc_size, 2)
elif self.mode == 'uniform':
samples = np.random.randint(-(patch_size - 2) // 2,
(patch_size // 2) + 1,
(desc_size * 2, 2))
samples = np.array(samples, dtype=np.int32)
pos1, pos2 = np.split(samples, 2)
pos1 = np.ascontiguousarray(pos1)
pos2 = np.ascontiguousarray(pos2)
# Removing keypoints that are within (patch_size / 2) distance from the
# image border
self.mask = _mask_border_keypoints(image.shape, keypoints,
patch_size // 2)
keypoints = np.array(keypoints[self.mask, :], dtype=np.intp,
order='C', copy=False)
self.descriptors = np.zeros((keypoints.shape[0], desc_size),
dtype=bool, order='C')
_brief_loop(image, self.descriptors.view(np.uint8), keypoints,
pos1, pos2)
开发者ID:borevitzlab,项目名称:scikit-image,代码行数:54,代码来源:brief.py
示例11: _apply
def _apply(func, image, selem, out, mask, shift_x, shift_y, s0, s1,
out_dtype=None):
assert_nD(image, 2)
image, selem, out, mask, max_bin = _handle_input(image, selem, out, mask,
out_dtype)
func(image, selem, shift_x=shift_x, shift_y=shift_y, mask=mask,
out=out, max_bin=max_bin, s0=s0, s1=s1)
return out.reshape(out.shape[:2])
开发者ID:JeanKossaifi,项目名称:scikit-image,代码行数:11,代码来源:bilateral.py
示例12: extract
def extract(self, image, keypoints, scales, orientations):
"""Extract rBRIEF binary descriptors for given keypoints in image.
Note that the keypoints must be extracted using the same `downscale`
and `n_scales` parameters. Additionally, if you want to extract both
keypoints and descriptors you should use the faster
`detect_and_extract`.
Parameters
----------
image : 2D array
Input image.
keypoints : (N, 2) array
Keypoint coordinates as ``(row, col)``.
scales : (N, ) array
Corresponding scales.
orientations : (N, ) array
Corresponding orientations in radians.
"""
assert_nD(image, 2)
pyramid = self._build_pyramid(image)
descriptors_list = []
mask_list = []
# Determine octaves from scales
octaves = (np.log(scales) / np.log(self.downscale)).astype(np.intp)
for octave in range(len(pyramid)):
# Mask for all keypoints in current octave
octave_mask = octaves == octave
if np.sum(octave_mask) > 0:
octave_image = np.ascontiguousarray(pyramid[octave])
octave_keypoints = keypoints[octave_mask]
octave_keypoints /= self.downscale ** octave
octave_orientations = orientations[octave_mask]
descriptors, mask = self._extract_octave(octave_image,
octave_keypoints,
octave_orientations)
descriptors_list.append(descriptors)
mask_list.append(mask)
self.descriptors = np.vstack(descriptors_list).view(np.bool)
self.mask_ = np.hstack(mask_list)
开发者ID:JeanKossaifi,项目名称:scikit-image,代码行数:53,代码来源:orb.py
示例13: __call__
def __call__(self, data):
"""Apply the filter to the given data.
Parameters
----------
data : (M,N) ndarray
"""
assert_nD(data, 2, 'data')
F, G = self._prepare(data)
out = np.dual.ifftn(F * G)
out = np.abs(_centre(out, data.shape))
return out
开发者ID:Rapternmn,项目名称:scikit-image,代码行数:13,代码来源:lpi_filter.py
示例14: gabor_filter
def gabor_filter(image, frequency, theta=0, bandwidth=1, sigma_x=None,
sigma_y=None, offset=0, mode='reflect', cval=0):
"""Return real and imaginary responses to Gabor filter.
The real and imaginary parts of the Gabor filter kernel are applied to the
image and the response is returned as a pair of arrays.
Frequency and orientation representations of the Gabor filter are similar
to those of the human visual system. It is especially suitable for texture
classification using Gabor filter banks.
Parameters
----------
image : array
Input image.
frequency : float
Frequency of the harmonic function.
theta : float
Orientation in radians. If 0, the harmonic is in the x-direction.
bandwidth : float
The bandwidth captured by the filter. For fixed bandwidth, `sigma_x`
and `sigma_y` will decrease with increasing frequency. This value is
ignored if `sigma_x` and `sigma_y` are set by the user.
sigma_x, sigma_y : float
Standard deviation in x- and y-directions. These directions apply to
the kernel *before* rotation. If `theta = pi/2`, then the kernel is
rotated 90 degrees so that `sigma_x` controls the *vertical* direction.
offset : float, optional
Phase offset of harmonic function in radians.
Returns
-------
real, imag : arrays
Filtered images using the real and imaginary parts of the Gabor filter
kernel.
References
----------
.. [1] http://en.wikipedia.org/wiki/Gabor_filter
.. [2] http://mplab.ucsd.edu/tutorials/gabor.pdf
"""
assert_nD(image, 2)
g = gabor_kernel(frequency, theta, bandwidth, sigma_x, sigma_y, offset)
filtered_real = ndimage.convolve(image, np.real(g), mode=mode, cval=cval)
filtered_imag = ndimage.convolve(image, np.imag(g), mode=mode, cval=cval)
return filtered_real, filtered_imag
开发者ID:JeanKossaifi,项目名称:scikit-image,代码行数:49,代码来源:_gabor.py
示例15: detect
def detect(self, image):
"""Detect oriented FAST keypoints along with the corresponding scale.
Parameters
----------
image : 2D array
Input image.
"""
assert_nD(image, 2)
pyramid = self._build_pyramid(image)
keypoints_list = []
orientations_list = []
scales_list = []
responses_list = []
for octave in range(len(pyramid)):
octave_image = np.ascontiguousarray(pyramid[octave])
keypoints, orientations, responses = \
self._detect_octave(octave_image)
keypoints_list.append(keypoints * self.downscale ** octave)
orientations_list.append(orientations)
scales_list.append(self.downscale ** octave
* np.ones(keypoints.shape[0], dtype=np.intp))
responses_list.append(responses)
keypoints = np.vstack(keypoints_list)
orientations = np.hstack(orientations_list)
scales = np.hstack(scales_list)
responses = np.hstack(responses_list)
if keypoints.shape[0] < self.n_keypoints:
self.keypoints = keypoints
self.scales = scales
self.orientations = orientations
self.responses = responses
else:
# Choose best n_keypoints according to Harris corner response
best_indices = responses.argsort()[::-1][:self.n_keypoints]
self.keypoints = keypoints[best_indices]
self.scales = scales[best_indices]
self.orientations = orientations[best_indices]
self.responses = responses[best_indices]
开发者ID:JeanKossaifi,项目名称:scikit-image,代码行数:48,代码来源:orb.py
示例16: sobel
def sobel(image, mask=None):
"""Find the edge magnitude using the Sobel transform.
Parameters
----------
image : 2-D array
Image to process.
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Sobel edge map.
See also
--------
scharr, prewitt, roberts, feature.canny
Notes
-----
Take the square root of the sum of the squares of the horizontal and
vertical Sobels to get a magnitude that's somewhat insensitive to
direction.
The 3x3 convolution kernel used in the horizontal and vertical Sobels is
an approximation of the gradient of the image (with some slight blurring
since 9 pixels are used to compute the gradient at a given pixel). As an
approximation of the gradient, the Sobel operator is not completely
rotation-invariant. The Scharr operator should be used for a better
rotation invariance.
Note that ``scipy.ndimage.sobel`` returns a directional Sobel which
has to be further processed to perform edge detection.
Examples
--------
>>> from skimage import data
>>> camera = data.camera()
>>> from skimage import filters
>>> edges = filters.sobel(camera)
"""
assert_nD(image, 2)
out = np.sqrt(sobel_h(image, mask)**2 + sobel_v(image, mask)**2)
out /= np.sqrt(2)
return out
开发者ID:borevitzlab,项目名称:scikit-image,代码行数:48,代码来源:edges.py
示例17: prewitt
def prewitt(image, mask=None):
"""Find the edge magnitude using the Prewitt transform.
Parameters
----------
image : 2-D array
Image to process.
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Prewitt edge map.
See also
--------
sobel, scharr
Notes
-----
Return the square root of the sum of squares of the horizontal
and vertical Prewitt transforms. The edge magnitude depends slightly
on edge directions, since the approximation of the gradient operator by
the Prewitt operator is not completely rotation invariant. For a better
rotation invariance, the Scharr operator should be used. The Sobel operator
has a better rotation invariance than the Prewitt operator, but a worse
rotation invariance than the Scharr operator.
Examples
--------
>>> from skimage import data
>>> camera = data.camera()
>>> from skimage import filters
>>> edges = filters.prewitt(camera)
"""
assert_nD(image, 2)
out = np.sqrt(prewitt_h(image, mask)**2 + prewitt_v(image, mask)**2)
out /= np.sqrt(2)
return out
开发者ID:borevitzlab,项目名称:scikit-image,代码行数:42,代码来源:edges.py
示例18: roberts
def roberts(image, mask=None):
"""Find the edge magnitude using Roberts' cross operator.
Parameters
----------
image : 2-D array
Image to process.
mask : 2-D array, optional
An optional mask to limit the application to a certain area.
Note that pixels surrounding masked regions are also masked to
prevent masked regions from affecting the result.
Returns
-------
output : 2-D array
The Roberts' Cross edge map.
"""
assert_nD(image, 2)
return np.sqrt(roberts_positive_diagonal(image, mask)**2 +
roberts_negative_diagonal(image, mask)**2)
开发者ID:Rapternmn,项目名称:scikit-image,代码行数:20,代码来源:edges.py
示例19: wiener
def wiener(data, impulse_response=None, filter_params={}, K=0.25,
predefined_filter=None):
"""Minimum Mean Square Error (Wiener) inverse filter.
Parameters
----------
data : (M,N) ndarray
Input data.
K : float or (M,N) ndarray
Ratio between power spectrum of noise and undegraded
image.
impulse_response : callable `f(r, c, **filter_params)`
Impulse response of the filter. See LPIFilter2D.__init__.
filter_params : dict
Additional keyword parameters to the impulse_response function.
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.
"""
assert_nD(data, 2, 'data')
if not isinstance(K, float):
assert_nD(K, 2, 'K')
if predefined_filter is None:
filt = LPIFilter2D(impulse_response, **filter_params)
else:
filt = predefined_filter
F, G = filt._prepare(data)
_min_limit(F)
H_mag_sqr = np.abs(F)**2
F = 1 / F * H_mag_sqr / (H_mag_sqr + K)
return _centre(np.abs(ifftshift(np.dual.ifftn(G * F))), data.shape)
开发者ID:Rapternmn,项目名称:scikit-image,代码行数:40,代码来源:lpi_filter.py
示例20: _handle_input
def _handle_input(image, selem, out, mask, out_dtype=None, pixel_size=1):
assert_nD(image, 2)
if image.dtype not in (np.uint8, np.uint16):
image = img_as_ubyte(image)
selem = np.ascontiguousarray(img_as_ubyte(selem > 0))
image = np.ascontiguousarray(image)
if mask is None:
mask = np.ones(image.shape, dtype=np.uint8)
else:
mask = img_as_ubyte(mask)
mask = np.ascontiguousarray(mask)
if image is out:
raise NotImplementedError("Cannot perform rank operation in place.")
if out is None:
if out_dtype is None:
out_dtype = image.dtype
out = np.empty(image.shape+(pixel_size,), dtype=out_dtype)
else:
if len(out.shape) == 2:
out = out.reshape(out.shape+(pixel_size,))
is_8bit = image.dtype in (np.uint8, np.int8)
if is_8bit:
max_bin = 255
else:
max_bin = max(4, image.max())
bitdepth = int(np.log2(max_bin))
if bitdepth > 10:
warnings.warn("Bitdepth of %d may result in bad rank filter "
"performance due to large number of bins." % bitdepth)
return image, selem, out, mask, max_bin
开发者ID:Rapternmn,项目名称:scikit-image,代码行数:39,代码来源:generic.py
注:本文中的skimage._shared.utils.assert_nD函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论