mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-16 11:27:48 +08:00
Use function pointer for different interpolation methods
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
|
||||
cdef inline double nearest_neighbour(double* image, int rows, int cols,
|
||||
double r, double c, char mode,
|
||||
double cval=*)
|
||||
double cval)
|
||||
|
||||
cdef inline double bilinear_interpolation(double* image, int rows, int cols,
|
||||
double r, double c, char mode,
|
||||
double cval=*)
|
||||
double cval)
|
||||
|
||||
cdef inline double get_pixel(double* image, int rows, int cols, int r, int c,
|
||||
char mode, double cval=*)
|
||||
char mode, double cval)
|
||||
|
||||
cdef inline int coord_map(int dim, int coord, char mode)
|
||||
|
||||
@@ -7,7 +7,7 @@ from libc.math cimport ceil, floor, round
|
||||
|
||||
cdef inline double nearest_neighbour(double* image, int rows, int cols,
|
||||
double r, double c, char mode,
|
||||
double cval=0):
|
||||
double cval):
|
||||
"""Nearest neighbour interpolation at a given position in the image.
|
||||
|
||||
Parameters
|
||||
@@ -31,7 +31,7 @@ cdef inline double nearest_neighbour(double* image, int rows, int cols,
|
||||
|
||||
cdef inline double bilinear_interpolation(double* image, int rows, int cols,
|
||||
double r, double c, char mode,
|
||||
double cval=0):
|
||||
double cval):
|
||||
"""Bilinear interpolation at a given position in the image.
|
||||
|
||||
Parameters
|
||||
@@ -65,7 +65,7 @@ cdef inline double bilinear_interpolation(double* image, int rows, int cols,
|
||||
|
||||
|
||||
cdef inline double get_pixel(double* image, int rows, int cols, int r, int c,
|
||||
char mode, double cval=0):
|
||||
char mode, double cval):
|
||||
"""Get a pixel from the image, taking wrapping mode into consideration.
|
||||
|
||||
Parameters
|
||||
|
||||
@@ -132,7 +132,7 @@ def _local_binary_pattern(np.ndarray[double, ndim=2] image,
|
||||
for c in range(image.shape[1]):
|
||||
for i in range(P):
|
||||
texture[i] = bilinear_interpolation(<double*>image.data,
|
||||
rows, cols, r + coords[i, 0], c + coords[i, 1], 'C')
|
||||
rows, cols, r + coords[i, 0], c + coords[i, 1], 'C', 0)
|
||||
# signed / thresholded texture
|
||||
for i in range(P):
|
||||
if texture[i] - image[r, c] >= 0:
|
||||
|
||||
@@ -111,14 +111,17 @@ def _warp_fast(np.ndarray image, np.ndarray H, output_shape=None, int order=1,
|
||||
cdef int rows = img.shape[0]
|
||||
cdef int cols = img.shape[1]
|
||||
|
||||
cdef double (*interp_func)(double*, int, int, double, double,
|
||||
char, double)
|
||||
if order == 0:
|
||||
interp_func = nearest_neighbour
|
||||
elif order == 1:
|
||||
interp_func = bilinear_interpolation
|
||||
|
||||
for tfr in range(out_r):
|
||||
for tfc in range(out_c):
|
||||
_matrix_transform(tfc, tfr, <double*>M.data, &c, &r)
|
||||
if order == 0:
|
||||
out[tfr, tfc] = nearest_neighbour(<double*>img.data, rows,
|
||||
cols, r, c, mode_c, cval)
|
||||
elif order == 1:
|
||||
out[tfr, tfc] = bilinear_interpolation(<double*>img.data, rows,
|
||||
cols, r, c, mode_c, cval)
|
||||
out[tfr, tfc] = interp_func(<double*>img.data, rows, cols, r, c,
|
||||
mode_c, cval)
|
||||
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user