Use function pointer for different interpolation methods

This commit is contained in:
Johannes Schönberger
2012-08-30 07:33:39 +02:00
parent 99e4264e15
commit 9b44e24f8e
4 changed files with 16 additions and 13 deletions
+3 -3
View File
@@ -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)
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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:
+9 -6
View File
@@ -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