mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-16 11:21:25 +08:00
Introducing the _prepare_grayscale_input_2D function in feature.util
This commit is contained in:
committed by
Johannes Schönberger
parent
43d90d0e9d
commit
fe9f1e75b8
@@ -1,8 +1,8 @@
|
||||
import numpy as np
|
||||
from scipy.ndimage.filters import gaussian_filter
|
||||
|
||||
from ..util import img_as_float
|
||||
from .util import _mask_border_keypoints, pairwise_hamming_distance
|
||||
from .util import (_mask_border_keypoints, pairwise_hamming_distance,
|
||||
_prepare_grayscale_input_2D)
|
||||
|
||||
from ._brief_cy import _brief_loop
|
||||
|
||||
@@ -129,11 +129,7 @@ def brief(image, keypoints, descriptor_size=256, mode='normal', patch_size=49,
|
||||
|
||||
np.random.seed(sample_seed)
|
||||
|
||||
image = np.squeeze(image)
|
||||
if image.ndim != 2:
|
||||
raise ValueError("Only 2-D gray-scale images supported.")
|
||||
|
||||
image = img_as_float(image)
|
||||
image = _prepare_grayscale_input_2D(image)
|
||||
|
||||
# Gaussian Low pass filtering to alleviate noise
|
||||
# sensitivity
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import numpy as np
|
||||
from scipy.ndimage.filters import maximum_filter, minimum_filter, convolve
|
||||
|
||||
from .util import _prepare_grayscale_input_2D
|
||||
|
||||
from skimage.transform import integral_image
|
||||
from skimage.feature import structure_tensor
|
||||
from skimage.util import img_as_float
|
||||
from skimage.morphology import octagon, star
|
||||
from skimage.feature.util import _mask_border_keypoints
|
||||
|
||||
@@ -175,9 +176,7 @@ def keypoints_censure(image, min_scale=1, max_scale=7, mode='DoB',
|
||||
# (4) Finally, we remove the border keypoints and return the keypoints
|
||||
# along with its corresponding scale.
|
||||
|
||||
image = np.squeeze(image)
|
||||
if image.ndim != 2:
|
||||
raise ValueError("Only 2-D gray-scale images supported.")
|
||||
image = _prepare_grayscale_input_2D(image)
|
||||
|
||||
mode = mode.lower()
|
||||
if mode not in ('dob', 'octagon', 'star'):
|
||||
@@ -187,7 +186,6 @@ def keypoints_censure(image, min_scale=1, max_scale=7, mode='DoB',
|
||||
raise ValueError('The scales must be >= 1 and the number of scales '
|
||||
'should be >= 3.')
|
||||
|
||||
image = img_as_float(image)
|
||||
image = np.ascontiguousarray(image)
|
||||
|
||||
# Generating all the scales
|
||||
|
||||
@@ -5,6 +5,8 @@ from skimage.color import rgb2grey
|
||||
from skimage.util import img_as_float, pad
|
||||
from skimage.feature import peak_local_max
|
||||
|
||||
from .util import _prepare_grayscale_input_2D
|
||||
|
||||
from corner_cy import _corner_fast
|
||||
|
||||
|
||||
@@ -84,9 +86,7 @@ def structure_tensor(image, sigma=1, mode='constant', cval=0):
|
||||
|
||||
"""
|
||||
|
||||
image = np.squeeze(image)
|
||||
if image.ndim != 2:
|
||||
raise ValueError("Only 2-D gray-scale images supported.")
|
||||
image = _prepare_grayscale_input_2D(image)
|
||||
|
||||
imx, imy = _compute_derivatives(image, mode=mode, cval=cval)
|
||||
|
||||
@@ -146,9 +146,7 @@ def hessian_matrix(image, sigma=1, mode='constant', cval=0):
|
||||
|
||||
"""
|
||||
|
||||
image = np.squeeze(image)
|
||||
if image.ndim != 2:
|
||||
raise ValueError("Only 2-D gray-scale images supported.")
|
||||
image = _prepare_grayscale_input_2D(image)
|
||||
|
||||
# window extent to the left and right, which covers > 99% of the normal
|
||||
# distribution
|
||||
@@ -576,11 +574,8 @@ def corner_fast(image, n=12, threshold=0.15):
|
||||
[8, 8]])
|
||||
|
||||
"""
|
||||
image = np.squeeze(image)
|
||||
if image.ndim != 2:
|
||||
raise ValueError("Only 2-D gray-scale images supported.")
|
||||
image = _prepare_grayscale_input_2D(image)
|
||||
|
||||
image = img_as_float(image)
|
||||
image = np.ascontiguousarray(image)
|
||||
response = _corner_fast(image, n, threshold)
|
||||
return response
|
||||
|
||||
@@ -8,7 +8,8 @@ from libc.float cimport DBL_MAX
|
||||
from libc.math cimport atan2
|
||||
|
||||
from skimage.color import rgb2grey
|
||||
from skimage.util import img_as_float
|
||||
|
||||
from .util import _prepare_grayscale_input_2D
|
||||
|
||||
|
||||
def corner_moravec(image, Py_ssize_t window_size=1):
|
||||
@@ -231,14 +232,12 @@ def corner_orientations(image, Py_ssize_t[:, :] corners, mask):
|
||||
|
||||
"""
|
||||
|
||||
image = np.squeeze(image)
|
||||
if image.ndim != 2:
|
||||
raise ValueError("Only 2-D gray-scale images supported.")
|
||||
image = _prepare_grayscale_input_2D(image)
|
||||
|
||||
if mask.shape[0] % 2 != 1 or mask.shape[1] % 2 != 1:
|
||||
raise ValueError("Size of mask must be uneven.")
|
||||
|
||||
cdef double[:, :] cimage = img_as_float(image)
|
||||
cdef double[:, :] cimage = image
|
||||
cdef char[:, ::1] cmask = np.ascontiguousarray(mask != 0, dtype=np.uint8)
|
||||
|
||||
cdef Py_ssize_t i, r, c, r0, c0
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import numpy as np
|
||||
|
||||
from ..util import img_as_float
|
||||
from .util import _mask_border_keypoints
|
||||
from .util import _mask_border_keypoints, _prepare_grayscale_input_2D
|
||||
|
||||
from skimage.feature import (corner_fast, corner_orientations, corner_peaks,
|
||||
corner_harris)
|
||||
@@ -85,9 +84,7 @@ def keypoints_orb(image, n_keypoints=200, fast_n=9, fast_threshold=0.20,
|
||||
array([0, 0, 0, 0, 1, 1, 1, 1])
|
||||
|
||||
"""
|
||||
image = np.squeeze(image)
|
||||
if image.ndim != 2:
|
||||
raise ValueError("Only 2-D gray-scale images supported.")
|
||||
image = _prepare_grayscale_input_2D(image)
|
||||
|
||||
pyramid = list(pyramid_gaussian(image, n_scales - 1, downscale))
|
||||
|
||||
@@ -184,9 +181,7 @@ def descriptor_orb(image, keypoints, orientations, scales,
|
||||
(8, 256)
|
||||
|
||||
"""
|
||||
image = np.squeeze(image)
|
||||
if image.ndim != 2:
|
||||
raise ValueError("Only 2-D gray-scale images supported.")
|
||||
image = _prepare_grayscale_input_2D(image)
|
||||
|
||||
image = img_as_float(image)
|
||||
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
import numpy as np
|
||||
|
||||
from ..util import img_as_float
|
||||
|
||||
|
||||
def _prepare_grayscale_input_2D(image):
|
||||
image = np.squeeze(image)
|
||||
if image.ndim != 2:
|
||||
raise ValueError("Only 2-D gray-scale images supported.")
|
||||
|
||||
return img_as_float(image)
|
||||
|
||||
|
||||
def _mask_border_keypoints(image, keypoints, dist):
|
||||
|
||||
Reference in New Issue
Block a user