From 2641df3497bc65d5d98c3365e8f3862b24499648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 30 Jun 2013 10:41:04 +0200 Subject: [PATCH] Use typed memoryviews in rank filter package --- skimage/filter/rank/core16_cy.pxd | 12 +- skimage/filter/rank/core16_cy.pyx | 74 ++++++------ skimage/filter/rank/core8_cy.pxd | 10 +- skimage/filter/rank/core8_cy.pyx | 67 +++++------ skimage/filter/rank/generic16_cy.pyx | 126 ++++++++++----------- skimage/filter/rank/generic8_cy.pyx | 143 ++++++++++++------------ skimage/filter/rank/percentile16_cy.pyx | 72 ++++++------ skimage/filter/rank/percentile8_cy.pyx | 69 ++++++------ 8 files changed, 275 insertions(+), 298 deletions(-) diff --git a/skimage/filter/rank/core16_cy.pxd b/skimage/filter/rank/core16_cy.pxd index 5586aea1..f13f0fd1 100644 --- a/skimage/filter/rank/core16_cy.pxd +++ b/skimage/filter/rank/core16_cy.pxd @@ -4,17 +4,17 @@ cimport numpy as cnp ctypedef cnp.uint16_t dtype_t -cdef int int_max(int a, int b) -cdef int int_min(int a, int b) +cdef dtype_t uint16_max(dtype_t a, dtype_t b) +cdef dtype_t uint16_min(dtype_t a, dtype_t b) # 16-bit core kernel receives extra information about data bitdepth cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t, Py_ssize_t, Py_ssize_t, Py_ssize_t, float, float, Py_ssize_t, Py_ssize_t), - cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask, - cnp.ndarray[dtype_t, ndim=2] out, + dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask, + dtype_t[:, ::1] out, char shift_x, char shift_y, Py_ssize_t bitdepth, float p0, float p1, Py_ssize_t s0, Py_ssize_t s1) except * diff --git a/skimage/filter/rank/core16_cy.pyx b/skimage/filter/rank/core16_cy.pyx index 63bcdff1..25592d39 100644 --- a/skimage/filter/rank/core16_cy.pyx +++ b/skimage/filter/rank/core16_cy.pyx @@ -10,33 +10,33 @@ from libc.stdlib cimport malloc, free from .core8_cy cimport is_in_mask -cdef inline int int_max(int a, int b): +cdef inline dtype_t uint16_max(dtype_t a, dtype_t b): return a if a >= b else b -cdef inline int int_min(int a, int b): +cdef inline dtype_t uint16_min(dtype_t a, dtype_t b): return a if a <= b else b -cdef inline void histogram_increment(Py_ssize_t * histo, float * pop, +cdef inline void histogram_increment(Py_ssize_t* histo, float* pop, dtype_t value): histo[value] += 1 pop[0] += 1 -cdef inline void histogram_decrement(Py_ssize_t * histo, float * pop, +cdef inline void histogram_decrement(Py_ssize_t* histo, float* pop, dtype_t value): histo[value] -= 1 pop[0] -= 1 -cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t, +cdef void _core16(dtype_t kernel(Py_ssize_t*, float, dtype_t, Py_ssize_t, Py_ssize_t, Py_ssize_t, float, float, Py_ssize_t, Py_ssize_t), - cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask, - cnp.ndarray[dtype_t, ndim=2] out, + dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask, + dtype_t[:, ::1] out, char shift_x, char shift_y, Py_ssize_t bitdepth, float p0, float p1, Py_ssize_t s0, Py_ssize_t s1) except *: """Compute histogram for each pixel neighborhood, apply kernel function and @@ -65,12 +65,8 @@ cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t, cdef Py_ssize_t maxbin = maxbin_list[bitdepth] cdef Py_ssize_t midbin = midbin_list[bitdepth] - assert (image < maxbin).all() - # define pointers to the data - cdef dtype_t * out_data = out.data - cdef dtype_t * image_data = image.data - cdef cnp.uint8_t * mask_data = mask.data + cdef char* mask_data = &mask[0, 0] # define local variable types cdef Py_ssize_t r, c, rr, cc, s, value, local_max, i, even_row @@ -84,19 +80,19 @@ cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t, cdef Py_ssize_t num_se_n, num_se_s, num_se_e, num_se_w # the current local histogram distribution - cdef Py_ssize_t * histo = malloc(maxbin * sizeof(Py_ssize_t)) + cdef Py_ssize_t* histo = malloc(maxbin * sizeof(Py_ssize_t)) # these lists contain the relative pixel row and column for each of the 4 # attack borders east, west, north and south e.g. se_e_r lists the rows of # the east structuring element border - cdef Py_ssize_t * se_e_r = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_e_c = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_w_r = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_w_c = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_n_r = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_n_c = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_s_r = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_s_c = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t* se_e_r = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t* se_e_c = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t* se_w_r = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t* se_w_c = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t* se_n_r = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t* se_n_c = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t* se_s_r = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t* se_s_c = malloc(max_se * sizeof(Py_ssize_t)) # build attack and release borders # by using difference along axis @@ -145,12 +141,12 @@ cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t, cc = c - centre_c if selem[r, c]: if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) r = 0 c = 0 # kernel ------------------------------------------- - out_data[r * cols + c] = kernel(histo, pop, image_data[r * cols + c], + out[r, c] = kernel(histo, pop, image[r, c], bitdepth, maxbin, midbin, p0, p1, s0, s1) # kernel ------------------------------------------- @@ -163,17 +159,17 @@ cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t, rr = r + se_e_r[s] cc = c + se_e_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) for s in range(num_se_w): rr = r + se_w_r[s] cc = c + se_w_c[s] - 1 if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_decrement(histo, &pop, image_data[rr * cols + cc]) + histogram_decrement(histo, &pop, image[rr, cc]) # kernel ------------------------------------------- - out_data[r * cols + c] = kernel( - histo, pop, image_data[r * cols + c], + out[r, c] = kernel( + histo, pop, image[r, c], bitdepth, maxbin, midbin, p0, p1, s0, s1) # kernel ------------------------------------------- @@ -186,16 +182,16 @@ cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t, rr = r + se_s_r[s] cc = c + se_s_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) for s in range(num_se_n): rr = r + se_n_r[s] - 1 cc = c + se_n_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_decrement(histo, &pop, image_data[rr * cols + cc]) + histogram_decrement(histo, &pop, image[rr, cc]) # kernel ------------------------------------------- - out_data[r * cols + c] = kernel(histo, pop, image_data[r * cols + c], + out[r, c] = kernel(histo, pop, image[r, c], bitdepth, maxbin, midbin, p0, p1, s0, s1) # kernel ------------------------------------------- @@ -205,17 +201,17 @@ cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t, rr = r + se_w_r[s] cc = c + se_w_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) for s in range(num_se_e): rr = r + se_e_r[s] cc = c + se_e_c[s] + 1 if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_decrement(histo, &pop, image_data[rr * cols + cc]) + histogram_decrement(histo, &pop, image[rr, cc]) # kernel ------------------------------------------- - out_data[r * cols + c] = kernel( - histo, pop, image_data[r * cols + c], + out[r, c] = kernel( + histo, pop, image[r, c], bitdepth, maxbin, midbin, p0, p1, s0, s1) # kernel ------------------------------------------- @@ -228,16 +224,16 @@ cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t, rr = r + se_s_r[s] cc = c + se_s_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) for s in range(num_se_n): rr = r + se_n_r[s] - 1 cc = c + se_n_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_decrement(histo, &pop, image_data[rr * cols + cc]) + histogram_decrement(histo, &pop, image[rr, cc]) # kernel ------------------------------------------- - out_data[r * cols + c] = kernel(histo, pop, image_data[r * cols + c], + out[r, c] = kernel(histo, pop, image[r, c], bitdepth, maxbin, midbin, p0, p1, s0, s1) # kernel ------------------------------------------- diff --git a/skimage/filter/rank/core8_cy.pxd b/skimage/filter/rank/core8_cy.pxd index d3b6d8c2..8d7f9744 100644 --- a/skimage/filter/rank/core8_cy.pxd +++ b/skimage/filter/rank/core8_cy.pxd @@ -10,16 +10,16 @@ cdef dtype_t uint8_min(dtype_t a, dtype_t b) cdef dtype_t is_in_mask(Py_ssize_t rows, Py_ssize_t cols, Py_ssize_t r, Py_ssize_t c, - dtype_t * mask) + char* mask) # 8-bit core kernel receives extra information about data inferior and superior # percentiles cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float, float, Py_ssize_t, Py_ssize_t), - cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask, - cnp.ndarray[dtype_t, ndim=2] out, + dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask, + dtype_t[:, ::1] out, char shift_x, char shift_y, float p0, float p1, Py_ssize_t s0, Py_ssize_t s1) except * diff --git a/skimage/filter/rank/core8_cy.pyx b/skimage/filter/rank/core8_cy.pyx index 79ae9bbf..b8d49a0f 100644 --- a/skimage/filter/rank/core8_cy.pyx +++ b/skimage/filter/rank/core8_cy.pyx @@ -31,7 +31,7 @@ cdef inline void histogram_decrement(Py_ssize_t * histo, float * pop, cdef inline dtype_t is_in_mask(Py_ssize_t rows, Py_ssize_t cols, Py_ssize_t r, Py_ssize_t c, - dtype_t * mask): + char* mask): """Check whether given coordinate is within image and mask is true.""" if r < 0 or r > rows - 1 or c < 0 or c > cols - 1: return 0 @@ -44,10 +44,10 @@ cdef inline dtype_t is_in_mask(Py_ssize_t rows, Py_ssize_t cols, cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float, float, Py_ssize_t, Py_ssize_t), - cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask, - cnp.ndarray[dtype_t, ndim=2] out, + dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask, + dtype_t[:, ::1] out, char shift_x, char shift_y, float p0, float p1, Py_ssize_t s0, Py_ssize_t s1) except *: """Compute histogram for each pixel neighborhood, apply kernel function and @@ -68,11 +68,7 @@ cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float, assert centre_r < srows assert centre_c < scols - # define pointers to the data - - cdef dtype_t * out_data = out.data - cdef dtype_t * image_data = image.data - cdef dtype_t * mask_data = mask.data + cdef char* mask_data = &mask[0, 0] # define local variable types cdef Py_ssize_t r, c, rr, cc, s, value, local_max, i, even_row @@ -87,19 +83,19 @@ cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float, cdef Py_ssize_t num_se_n, num_se_s, num_se_e, num_se_w # the current local histogram distribution - cdef Py_ssize_t * histo = malloc(256 * sizeof(Py_ssize_t)) + cdef Py_ssize_t * histo = malloc(256 * sizeof(Py_ssize_t)) # these lists contain the relative pixel row and column for each of the 4 # attack borders east, west, north and south e.g. se_e_r lists the rows of # the east structuring element border - cdef Py_ssize_t * se_e_r = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_e_c = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_w_r = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_w_c = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_n_r = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_n_c = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_s_r = malloc(max_se * sizeof(Py_ssize_t)) - cdef Py_ssize_t * se_s_c = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t * se_e_r = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t * se_e_c = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t * se_w_r = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t * se_w_c = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t * se_n_r = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t * se_n_c = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t * se_s_r = malloc(max_se * sizeof(Py_ssize_t)) + cdef Py_ssize_t * se_s_c = malloc(max_se * sizeof(Py_ssize_t)) # build attack and release borders # by using difference along axis @@ -149,12 +145,12 @@ cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float, cc = c - centre_c if selem[r, c]: if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) r = 0 c = 0 # kernel ------------------------------------------------------------------- - out_data[r * cols + c] = kernel(histo, pop, image_data[r * cols + c], + out[r, c] = kernel(histo, pop, image[r, c], p0, p1, s0, s1) # kernel ------------------------------------------------------------------- @@ -167,17 +163,17 @@ cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float, rr = r + se_e_r[s] cc = c + se_e_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) for s in range(num_se_w): rr = r + se_w_r[s] cc = c + se_w_c[s] - 1 if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_decrement(histo, &pop, image_data[rr * cols + cc]) + histogram_decrement(histo, &pop, image[rr, cc]) # kernel ----------------------------------------------------------- - out_data[r * cols + c] = \ - kernel(histo, pop, image_data[r * cols + c], p0, p1, s0, s1) + out[r, c] = \ + kernel(histo, pop, image[r, c], p0, p1, s0, s1) # kernel ----------------------------------------------------------- r += 1 # pass to the next row @@ -189,16 +185,16 @@ cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float, rr = r + se_s_r[s] cc = c + se_s_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) for s in range(num_se_n): rr = r + se_n_r[s] - 1 cc = c + se_n_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_decrement(histo, &pop, image_data[rr * cols + cc]) + histogram_decrement(histo, &pop, image[rr, cc]) # kernel --------------------------------------------------------------- - out_data[r * cols + c] = kernel(histo, pop, image_data[r * cols + c], + out[r, c] = kernel(histo, pop, image[r, c], p0, p1, s0, s1) # kernel --------------------------------------------------------------- @@ -208,17 +204,17 @@ cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float, rr = r + se_w_r[s] cc = c + se_w_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) for s in range(num_se_e): rr = r + se_e_r[s] cc = c + se_e_c[s] + 1 if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_decrement(histo, &pop, image_data[rr * cols + cc]) + histogram_decrement(histo, &pop, image[rr, cc]) # kernel ----------------------------------------------------------- - out_data[r * cols + c] = kernel( - histo, pop, image_data[r * cols + c], p0, p1, s0, s1) + out[r, c] = kernel( + histo, pop, image[r, c], p0, p1, s0, s1) # kernel ----------------------------------------------------------- r += 1 # pass to the next row @@ -230,21 +226,20 @@ cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float, rr = r + se_s_r[s] cc = c + se_s_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_increment(histo, &pop, image_data[rr * cols + cc]) + histogram_increment(histo, &pop, image[rr, cc]) for s in range(num_se_n): rr = r + se_n_r[s] - 1 cc = c + se_n_c[s] if is_in_mask(rows, cols, rr, cc, mask_data): - histogram_decrement(histo, &pop, image_data[rr * cols + cc]) + histogram_decrement(histo, &pop, image[rr, cc]) # kernel --------------------------------------------------------------- - out_data[r * cols + c] = kernel(histo, pop, image_data[r * cols + c], + out[r, c] = kernel(histo, pop, image[r, c], p0, p1, s0, s1) # kernel --------------------------------------------------------------- # release memory allocated by malloc - free(se_e_r) free(se_e_c) free(se_w_r) diff --git a/skimage/filter/rank/generic16_cy.pyx b/skimage/filter/rank/generic16_cy.pyx index eace0afa..7b2a8088 100644 --- a/skimage/filter/rank/generic16_cy.pyx +++ b/skimage/filter/rank/generic16_cy.pyx @@ -5,17 +5,13 @@ cimport numpy as cnp from libc.math cimport log -from .core16_cy cimport _core16 +from .core16_cy cimport dtype_t, _core16 # ----------------------------------------------------------------- # kernels uint16 take extra parameter for defining the bitdepth # ----------------------------------------------------------------- - -ctypedef cnp.uint16_t dtype_t - - cdef inline dtype_t kernel_autolevel(Py_ssize_t * histo, float pop, dtype_t g, Py_ssize_t bitdepth, Py_ssize_t maxbin, Py_ssize_t midbin, @@ -287,136 +283,136 @@ cdef inline dtype_t kernel_entropy(Py_ssize_t * histo, float pop, # ----------------------------------------------------------------- -def autolevel(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def autolevel(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_autolevel, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def bottomhat(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def bottomhat(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_bottomhat, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def equalize(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def equalize(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_equalize, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def gradient(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def gradient(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_gradient, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def maximum(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def maximum(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_maximum, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def mean(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def mean(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_mean, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def meansubtraction(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def meansubtraction(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_meansubtraction, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def median(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def median(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_median, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def minimum(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def minimum(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_minimum, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def morph_contr_enh(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def morph_contr_enh(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_morph_contr_enh, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def modal(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def modal(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_modal, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def pop(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def pop(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_pop, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def threshold(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def threshold(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_threshold, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def tophat(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def tophat(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_tophat, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) -def entropy(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def entropy(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, Py_ssize_t bitdepth=8): _core16(kernel_entropy, image, selem, mask, out, shift_x, shift_y, bitdepth, 0, 0, 0, 0) diff --git a/skimage/filter/rank/generic8_cy.pyx b/skimage/filter/rank/generic8_cy.pyx index 1cccc21f..62749041 100644 --- a/skimage/filter/rank/generic8_cy.pyx +++ b/skimage/filter/rank/generic8_cy.pyx @@ -5,7 +5,7 @@ cimport numpy as cnp from libc.math cimport log -from .core8_cy cimport _core8 +from .core8_cy cimport dtype_t, _core8 # ----------------------------------------------------------------- @@ -13,9 +13,6 @@ from .core8_cy cimport _core8 # ----------------------------------------------------------------- -ctypedef cnp.uint8_t dtype_t - - cdef inline dtype_t kernel_autolevel(Py_ssize_t * histo, float pop, dtype_t g, float p0, float p1, Py_ssize_t s0, Py_ssize_t s1): @@ -330,154 +327,154 @@ cdef inline dtype_t kernel_otsu(Py_ssize_t * histo, float pop, dtype_t g, # ----------------------------------------------------------------- -def autolevel(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def autolevel(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_autolevel, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def bottomhat(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def bottomhat(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_bottomhat, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def equalize(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def equalize(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_equalize, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def gradient(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def gradient(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_gradient, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def maximum(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def maximum(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_maximum, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def mean(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def mean(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_mean, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def meansubtraction(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, - char shift_x=0, char shift_y=0): +def meansubtraction(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, + char shift_x=0, char shift_y=0): _core8(kernel_meansubtraction, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def median(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def median(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_median, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def minimum(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def minimum(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_minimum, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def morph_contr_enh(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def morph_contr_enh(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_morph_contr_enh, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def modal(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def modal(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_modal, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def pop(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def pop(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_pop, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def threshold(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def threshold(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_threshold, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def tophat(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def tophat(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_tophat, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def noise_filter(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def noise_filter(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_noise_filter, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def entropy(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def entropy(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_entropy, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) -def otsu(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def otsu(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0): _core8(kernel_otsu, image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0) diff --git a/skimage/filter/rank/percentile16_cy.pyx b/skimage/filter/rank/percentile16_cy.pyx index 368bec0e..8680aae4 100644 --- a/skimage/filter/rank/percentile16_cy.pyx +++ b/skimage/filter/rank/percentile16_cy.pyx @@ -4,17 +4,13 @@ #cython: wraparound=False cimport numpy as cnp -from .core16_cy cimport _core16, int_min, int_max +from .core16_cy cimport dtype_t, _core16, uint16_min, uint16_max # ----------------------------------------------------------------- # kernels uint16 (SOFT version using percentiles) # ----------------------------------------------------------------- - -ctypedef cnp.uint16_t dtype_t - - cdef inline dtype_t kernel_autolevel(Py_ssize_t * histo, float pop, dtype_t g, Py_ssize_t bitdepth, Py_ssize_t maxbin, Py_ssize_t midbin, @@ -41,7 +37,7 @@ cdef inline dtype_t kernel_autolevel(Py_ssize_t * histo, float pop, delta = imax - imin if delta > 0: return (1.0 * (maxbin - 1) - * (int_min(int_max(imin, g), imax) + * (uint16_min(uint16_max(imin, g), imax) - imin) / delta) else: return (imax - imin) @@ -233,10 +229,10 @@ cdef inline dtype_t kernel_threshold(Py_ssize_t * histo, float pop, # ----------------------------------------------------------------- -def autolevel(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def autolevel(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """bottom hat @@ -245,10 +241,10 @@ def autolevel(cnp.ndarray[dtype_t, ndim=2] image, bitdepth, p0, p1, 0, 0) -def gradient(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def gradient(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """return p0,p1 percentile gradient @@ -257,10 +253,10 @@ def gradient(cnp.ndarray[dtype_t, ndim=2] image, bitdepth, p0, p1, 0, 0) -def mean(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def mean(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """return mean between [p0 and p1] percentiles @@ -269,10 +265,10 @@ def mean(cnp.ndarray[dtype_t, ndim=2] image, bitdepth, p0, p1, 0, 0) -def mean_subtraction(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def mean_subtraction(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """return original - mean between [p0 and p1] percentiles *.5 +127 @@ -282,10 +278,10 @@ def mean_subtraction(cnp.ndarray[dtype_t, ndim=2] image, bitdepth, p0, p1, 0, 0) -def morph_contr_enh(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def morph_contr_enh(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """reforce contrast using percentiles @@ -294,10 +290,10 @@ def morph_contr_enh(cnp.ndarray[dtype_t, ndim=2] image, bitdepth, p0, p1, 0, 0) -def percentile(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def percentile(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0.): """return p0 percentile @@ -306,10 +302,10 @@ def percentile(cnp.ndarray[dtype_t, ndim=2] image, bitdepth, p0, .0, 0, 0) -def pop(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def pop(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """return nb of pixels between [p0 and p1] @@ -318,10 +314,10 @@ def pop(cnp.ndarray[dtype_t, ndim=2] image, bitdepth, p0, p1, 0, 0) -def threshold(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[cnp.uint8_t, ndim=2] selem, - cnp.ndarray[cnp.uint8_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def threshold(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0.): """return (maxbin-1) if g > percentile p0 diff --git a/skimage/filter/rank/percentile8_cy.pyx b/skimage/filter/rank/percentile8_cy.pyx index 7f514f89..6c37cf66 100644 --- a/skimage/filter/rank/percentile8_cy.pyx +++ b/skimage/filter/rank/percentile8_cy.pyx @@ -4,7 +4,7 @@ #cython: wraparound=False cimport numpy as cnp -from .core8_cy cimport _core8, uint8_max, uint8_min +from .core8_cy cimport dtype_t, _core8, uint8_max, uint8_min # ----------------------------------------------------------------- @@ -12,9 +12,6 @@ from .core8_cy cimport _core8, uint8_max, uint8_min # ----------------------------------------------------------------- -ctypedef cnp.uint8_t dtype_t - - cdef inline dtype_t kernel_autolevel(Py_ssize_t * histo, float pop, dtype_t g, float p0, float p1, Py_ssize_t s0, Py_ssize_t s1): @@ -206,10 +203,10 @@ cdef inline dtype_t kernel_threshold(Py_ssize_t * histo, float pop, # ----------------------------------------------------------------- -def autolevel(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def autolevel(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """autolevel """ @@ -217,10 +214,10 @@ def autolevel(cnp.ndarray[dtype_t, ndim=2] image, 0, 0) -def gradient(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def gradient(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return p0,p1 percentile gradient """ @@ -228,10 +225,10 @@ def gradient(cnp.ndarray[dtype_t, ndim=2] image, 0, 0) -def mean(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def mean(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return mean between [p0 and p1] percentiles """ @@ -239,10 +236,10 @@ def mean(cnp.ndarray[dtype_t, ndim=2] image, 0, 0) -def mean_subtraction(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def mean_subtraction(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return original - mean between [p0 and p1] percentiles *.5 +127 """ @@ -250,10 +247,10 @@ def mean_subtraction(cnp.ndarray[dtype_t, ndim=2] image, p0, p1, 0, 0) -def morph_contr_enh(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def morph_contr_enh(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """reforce contrast using percentiles """ @@ -261,10 +258,10 @@ def morph_contr_enh(cnp.ndarray[dtype_t, ndim=2] image, p0, p1, 0, 0) -def percentile(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def percentile(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, float p0=0.): """return p0 percentile """ @@ -272,10 +269,10 @@ def percentile(cnp.ndarray[dtype_t, ndim=2] image, p0, 0., 0, 0) -def pop(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def pop(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return nb of pixels between [p0 and p1] """ @@ -283,10 +280,10 @@ def pop(cnp.ndarray[dtype_t, ndim=2] image, 0, 0) -def threshold(cnp.ndarray[dtype_t, ndim=2] image, - cnp.ndarray[dtype_t, ndim=2] selem, - cnp.ndarray[dtype_t, ndim=2] mask=None, - cnp.ndarray[dtype_t, ndim=2] out=None, +def threshold(dtype_t[:, ::1] image, + char[:, ::1] selem, + char[:, ::1] mask=None, + dtype_t[:, ::1] out=None, char shift_x=0, char shift_y=0, float p0=0.): """return 255 if g > percentile p0 """