From 9b44e24f8ed9d711b8127ad8097acb9a0855304d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Thu, 30 Aug 2012 07:33:39 +0200 Subject: [PATCH] Use function pointer for different interpolation methods --- skimage/_shared/interpolation.pxd | 6 +++--- skimage/_shared/interpolation.pyx | 6 +++--- skimage/feature/_texture.pyx | 2 +- skimage/transform/_warps_cy.pyx | 15 +++++++++------ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/skimage/_shared/interpolation.pxd b/skimage/_shared/interpolation.pxd index c883d00d..3e8e74e9 100644 --- a/skimage/_shared/interpolation.pxd +++ b/skimage/_shared/interpolation.pxd @@ -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) diff --git a/skimage/_shared/interpolation.pyx b/skimage/_shared/interpolation.pyx index 83722aba..63f5b70c 100644 --- a/skimage/_shared/interpolation.pyx +++ b/skimage/_shared/interpolation.pyx @@ -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 diff --git a/skimage/feature/_texture.pyx b/skimage/feature/_texture.pyx index 5fb53e90..70a446bb 100644 --- a/skimage/feature/_texture.pyx +++ b/skimage/feature/_texture.pyx @@ -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(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: diff --git a/skimage/transform/_warps_cy.pyx b/skimage/transform/_warps_cy.pyx index 2851a728..5903380e 100644 --- a/skimage/transform/_warps_cy.pyx +++ b/skimage/transform/_warps_cy.pyx @@ -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, M.data, &c, &r) - if order == 0: - out[tfr, tfc] = nearest_neighbour(img.data, rows, - cols, r, c, mode_c, cval) - elif order == 1: - out[tfr, tfc] = bilinear_interpolation(img.data, rows, - cols, r, c, mode_c, cval) + out[tfr, tfc] = interp_func(img.data, rows, cols, r, c, + mode_c, cval) return out