diff --git a/skimage/rank/__init__.py b/skimage/rank/__init__.py index 8b0e3f5b..e69de29b 100644 --- a/skimage/rank/__init__.py +++ b/skimage/rank/__init__.py @@ -1 +0,0 @@ -from .crank import * diff --git a/skimage/rank/core.pxd b/skimage/rank/_core.pxd similarity index 100% rename from skimage/rank/core.pxd rename to skimage/rank/_core.pxd diff --git a/skimage/rank/core16.pxd b/skimage/rank/_core16.pxd similarity index 99% rename from skimage/rank/core16.pxd rename to skimage/rank/_core16.pxd index 9973025f..ddd8c637 100644 --- a/skimage/rank/core16.pxd +++ b/skimage/rank/_core16.pxd @@ -22,7 +22,7 @@ cdef inline int int_min(int a, int b): return a if a <= b else b # 16 bit core kernel receives extra information about data bitdepth #--------------------------------------------------------------------------- -cdef inline rank16(np.uint16_t kernel(int*, float, np.uint16_t, int ,int,int ), +cdef inline _core16(np.uint16_t kernel(int*, float, np.uint16_t, int ,int,int ), np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, np.ndarray[np.uint8_t, ndim=2] mask, diff --git a/skimage/rank/core16b.pxd b/skimage/rank/_core16b.pxd similarity index 99% rename from skimage/rank/core16b.pxd rename to skimage/rank/_core16b.pxd index 38832c11..fefac53e 100644 --- a/skimage/rank/core16b.pxd +++ b/skimage/rank/_core16b.pxd @@ -22,7 +22,7 @@ cdef inline int int_min(int a, int b): return a if a <= b else b # 16 bit core kernel receives extra information about data bitdepth and bilateral interval #--------------------------------------------------------------------------- -cdef inline rank16b(np.uint16_t kernel(int*, float, np.uint16_t, int ,int,int,int,int), +cdef inline _core16b(np.uint16_t kernel(int*, float, np.uint16_t, int ,int,int,int,int), np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, np.ndarray[np.uint8_t, ndim=2] mask, diff --git a/skimage/rank/core16p.pxd b/skimage/rank/_core16p.pxd similarity index 98% rename from skimage/rank/core16p.pxd rename to skimage/rank/_core16p.pxd index dbf51c54..0d698cee 100644 --- a/skimage/rank/core16p.pxd +++ b/skimage/rank/_core16p.pxd @@ -22,7 +22,7 @@ cdef inline int int_min(int a, int b): return a if a <= b else b # 16 bit core kernel receives extra information about data inferior and superior percentiles #--------------------------------------------------------------------------- -cdef inline rank16_percentile(np.uint16_t kernel(int*, float, np.uint16_t,int,int,int, float, float), +cdef inline _core16p(np.uint16_t kernel(int*, float, np.uint16_t,int,int,int, float, float), np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, np.ndarray[np.uint8_t, ndim=2] mask, diff --git a/skimage/rank/core8.pxd b/skimage/rank/_core8.pxd similarity index 99% rename from skimage/rank/core8.pxd rename to skimage/rank/_core8.pxd index 0c901c8b..3d5ddac3 100644 --- a/skimage/rank/core8.pxd +++ b/skimage/rank/_core8.pxd @@ -22,7 +22,7 @@ cdef inline int int_min(int a, int b): return a if a <= b else b # 8 bit core kernel #--------------------------------------------------------------------------- -cdef inline rank8(np.uint8_t kernel(int*, float, np.uint8_t), +cdef inline _core8(np.uint8_t kernel(int*, float, np.uint8_t), np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, np.ndarray[np.uint8_t, ndim=2] mask, diff --git a/skimage/rank/core8p.pxd b/skimage/rank/_core8p.pxd similarity index 99% rename from skimage/rank/core8p.pxd rename to skimage/rank/_core8p.pxd index 25e3ffcf..dfab17be 100644 --- a/skimage/rank/core8p.pxd +++ b/skimage/rank/_core8p.pxd @@ -22,7 +22,7 @@ cdef inline int int_min(int a, int b): return a if a <= b else b # 8 bit core kernel receives extra information about data inferior and superior percentiles #--------------------------------------------------------------------------- -cdef inline rank8_percentile(np.uint8_t kernel(int*, float, np.uint8_t, float, float), +cdef inline _core8p(np.uint8_t kernel(int*, float, np.uint8_t, float, float), np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, np.ndarray[np.uint8_t, ndim=2] mask, diff --git a/skimage/rank/crank16.pyx b/skimage/rank/_crank16.pyx similarity index 90% rename from skimage/rank/crank16.pyx rename to skimage/rank/_crank16.pyx index cd0bacd4..e1e64bed 100644 --- a/skimage/rank/crank16.pyx +++ b/skimage/rank/_crank16.pyx @@ -15,7 +15,7 @@ import numpy as np cimport numpy as np # import main loop -from core16 cimport rank16 +from _core16 cimport _core16 # ----------------------------------------------------------------- # kernels uint16 take extra parameter for defining the bitdepth @@ -198,7 +198,7 @@ def autolevel(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """bottom hat """ - return rank16(kernel_autolevel,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_autolevel,image,selem,mask,out,shift_x,shift_y,bitdepth) def bottomhat(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -207,7 +207,7 @@ def bottomhat(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """bottom hat """ - return rank16(kernel_bottomhat,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_bottomhat,image,selem,mask,out,shift_x,shift_y,bitdepth) def egalise(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -216,7 +216,7 @@ def egalise(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """local egalisation of the gray level """ - return rank16(kernel_egalise,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_egalise,image,selem,mask,out,shift_x,shift_y,bitdepth) def gradient(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -225,7 +225,7 @@ def gradient(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """local maximum - local minimum gray level """ - return rank16(kernel_gradient,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_gradient,image,selem,mask,out,shift_x,shift_y,bitdepth) def maximum(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -234,7 +234,7 @@ def maximum(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """local maximum gray level """ - return rank16(kernel_maximum,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_maximum,image,selem,mask,out,shift_x,shift_y,bitdepth) def mean(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -243,7 +243,7 @@ def mean(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """average gray level (clipped on uint8) """ - return rank16(kernel_mean,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_mean,image,selem,mask,out,shift_x,shift_y,bitdepth) def meansubstraction(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -252,7 +252,7 @@ def meansubstraction(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """(g - average gray level)/2+midbin (clipped on uint8) """ - return rank16(kernel_meansubstraction,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_meansubstraction,image,selem,mask,out,shift_x,shift_y,bitdepth) def median(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -261,7 +261,7 @@ def median(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """local median """ - return rank16(kernel_median,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_median,image,selem,mask,out,shift_x,shift_y,bitdepth) def minimum(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -270,7 +270,7 @@ def minimum(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """local minimum gray level """ - return rank16(kernel_minimum,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_minimum,image,selem,mask,out,shift_x,shift_y,bitdepth) def morph_contr_enh(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -279,7 +279,7 @@ def morph_contr_enh(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """morphological contrast enhancement """ - return rank16(kernel_morph_contr_enh,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_morph_contr_enh,image,selem,mask,out,shift_x,shift_y,bitdepth) def modal(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -288,7 +288,7 @@ def modal(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """local mode """ - return rank16(kernel_modal,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_modal,image,selem,mask,out,shift_x,shift_y,bitdepth) def pop(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -297,7 +297,7 @@ def pop(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """returns the number of actual pixels of the structuring element inside the mask """ - return rank16(kernel_pop,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_pop,image,selem,mask,out,shift_x,shift_y,bitdepth) def threshold(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -306,7 +306,7 @@ def threshold(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """returns maxbin-1 if gray level higher than local mean, 0 else """ - return rank16(kernel_threshold,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_threshold,image,selem,mask,out,shift_x,shift_y,bitdepth) def tophat(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -315,4 +315,4 @@ def tophat(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8): """top hat """ - return rank16(kernel_tophat,image,selem,mask,out,shift_x,shift_y,bitdepth) + return _core16(kernel_tophat,image,selem,mask,out,shift_x,shift_y,bitdepth) diff --git a/skimage/rank/crank16_bilateral.pyx b/skimage/rank/_crank16_bilateral.pyx similarity index 98% rename from skimage/rank/crank16_bilateral.pyx rename to skimage/rank/_crank16_bilateral.pyx index 313b83d6..440d28e3 100644 --- a/skimage/rank/crank16_bilateral.pyx +++ b/skimage/rank/_crank16_bilateral.pyx @@ -15,7 +15,7 @@ import numpy as np cimport numpy as np # import main loop -from core16b cimport rank16b +from _core16b cimport _core16b # ----------------------------------------------------------------- # kernels uint16 take extra parameter for defining the bitdepth @@ -257,7 +257,7 @@ def mean(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8, int s0=1, int s1=1): """average gray level (clipped on uint8) """ - return rank16b(kernel_mean,image,selem,mask,out,shift_x,shift_y,bitdepth,s0,s1) + return _core16b(kernel_mean,image,selem,mask,out,shift_x,shift_y,bitdepth,s0,s1) #def meansubstraction(np.ndarray[np.uint16_t, ndim=2] image, # np.ndarray[np.uint8_t, ndim=2] selem, @@ -311,7 +311,7 @@ def pop(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8, int s0=1, int s1=1): """returns the number of actual pixels of the structuring element inside the mask """ - return rank16b(kernel_pop,image,selem,mask,out,shift_x,shift_y,bitdepth,s0,s1) + return _core16b(kernel_pop,image,selem,mask,out,shift_x,shift_y,bitdepth,s0,s1) #def threshold(np.ndarray[np.uint16_t, ndim=2] image, # np.ndarray[np.uint8_t, ndim=2] selem, diff --git a/skimage/rank/crank16_percentiles.pyx b/skimage/rank/_crank16_percentiles.pyx similarity index 90% rename from skimage/rank/crank16_percentiles.pyx rename to skimage/rank/_crank16_percentiles.pyx index 7756bc19..54c25d40 100644 --- a/skimage/rank/crank16_percentiles.pyx +++ b/skimage/rank/_crank16_percentiles.pyx @@ -15,7 +15,7 @@ import numpy as np cimport numpy as np # import main loop -from core16p cimport rank16_percentile +from _core16p cimport _core16p # ----------------------------------------------------------------- # kernels uint8 (SOFT version using percentiles) @@ -194,7 +194,7 @@ def autolevel(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """bottom hat """ - return rank16_percentile(kernel_autolevel,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) + return _core16p(kernel_autolevel,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) def gradient(np.ndarray[np.uint16_t, ndim=2] image, @@ -204,7 +204,7 @@ def gradient(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """return p0,p1 percentile gradient """ - return rank16_percentile(kernel_gradient,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) + return _core16p(kernel_gradient,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) def mean(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -213,7 +213,7 @@ def mean(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """return mean between [p0 and p1] percentiles """ - return rank16_percentile(kernel_mean,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) + return _core16p(kernel_mean,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) def mean_substraction(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -222,7 +222,7 @@ def mean_substraction(np.ndarray[np.uint16_t, ndim=2] image, 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 """ - return rank16_percentile(kernel_mean_substraction,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) + return _core16p(kernel_mean_substraction,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) def morph_contr_enh(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -231,7 +231,7 @@ def morph_contr_enh(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """reforce contrast using percentiles """ - return rank16_percentile(kernel_morph_contr_enh,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) + return _core16p(kernel_morph_contr_enh,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) def percentile(np.ndarray[np.uint16_t, ndim=2] image, @@ -241,7 +241,7 @@ def percentile(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """return p0 percentile """ - return rank16_percentile(kernel_percentile,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) + return _core16p(kernel_percentile,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) def pop(np.ndarray[np.uint16_t, ndim=2] image, @@ -251,7 +251,7 @@ def pop(np.ndarray[np.uint16_t, ndim=2] image, 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] """ - return rank16_percentile(kernel_pop,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) + return _core16p(kernel_pop,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) def threshold(np.ndarray[np.uint16_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -260,4 +260,4 @@ def threshold(np.ndarray[np.uint16_t, ndim=2] image, char shift_x=0, char shift_y=0, int bitdepth=8, float p0=0., float p1=0.): """return (maxbin-1) if g > percentile p0 """ - return rank16_percentile(kernel_threshold,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) + return _core16p(kernel_threshold,image,selem,mask,out,shift_x,shift_y,bitdepth,p0,p1) diff --git a/skimage/rank/crank.pyx b/skimage/rank/_crank8.pyx similarity index 90% rename from skimage/rank/crank.pyx rename to skimage/rank/_crank8.pyx index 59016eed..cb74021e 100644 --- a/skimage/rank/crank.pyx +++ b/skimage/rank/_crank8.pyx @@ -15,7 +15,7 @@ import numpy as np cimport numpy as np # import main loop -from core8 cimport rank8 +from _core8 cimport _core8 # ----------------------------------------------------------------- # kernels uint8 @@ -199,7 +199,7 @@ def autolevel(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """bottom hat """ - return rank8(kernel_autolevel,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_autolevel,image,selem,mask,out,shift_x,shift_y) def bottomhat(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -208,7 +208,7 @@ def bottomhat(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """bottom hat """ - return rank8(kernel_bottomhat,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_bottomhat,image,selem,mask,out,shift_x,shift_y) def egalise(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -217,7 +217,7 @@ def egalise(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """local egalisation of the gray level """ - return rank8(kernel_egalise,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_egalise,image,selem,mask,out,shift_x,shift_y) def gradient(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -226,7 +226,7 @@ def gradient(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """local maximum - local minimum gray level """ - return rank8(kernel_gradient,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_gradient,image,selem,mask,out,shift_x,shift_y) def maximum(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -235,7 +235,7 @@ def maximum(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """local maximum gray level """ - return rank8(kernel_maximum,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_maximum,image,selem,mask,out,shift_x,shift_y) def mean(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -244,7 +244,7 @@ def mean(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """average gray level (clipped on uint8) """ - return rank8(kernel_mean,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_mean,image,selem,mask,out,shift_x,shift_y) def meansubstraction(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -253,7 +253,7 @@ def meansubstraction(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """(g - average gray level)/2+127 (clipped on uint8) """ - return rank8(kernel_meansubstraction,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_meansubstraction,image,selem,mask,out,shift_x,shift_y) def median(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -262,7 +262,7 @@ def median(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """local median """ - return rank8(kernel_median,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_median,image,selem,mask,out,shift_x,shift_y) def minimum(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -271,7 +271,7 @@ def minimum(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """local minimum gray level """ - return rank8(kernel_minimum,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_minimum,image,selem,mask,out,shift_x,shift_y) def morph_contr_enh(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -280,7 +280,7 @@ def morph_contr_enh(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """morphological contrast enhancement """ - return rank8(kernel_morph_contr_enh,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_morph_contr_enh,image,selem,mask,out,shift_x,shift_y) def modal(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -289,7 +289,7 @@ def modal(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """local mode """ - return rank8(kernel_modal,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_modal,image,selem,mask,out,shift_x,shift_y) def pop(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -298,7 +298,7 @@ def pop(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """returns the number of actual pixels of the structuring element inside the mask """ - return rank8(kernel_pop,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_pop,image,selem,mask,out,shift_x,shift_y) def threshold(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -307,7 +307,7 @@ def threshold(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """returns 255 if gray level higher than local mean, 0 else """ - return rank8(kernel_threshold,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_threshold,image,selem,mask,out,shift_x,shift_y) def tophat(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -316,5 +316,5 @@ def tophat(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0): """top hat """ - return rank8(kernel_tophat,image,selem,mask,out,shift_x,shift_y) + return _core8(kernel_tophat,image,selem,mask,out,shift_x,shift_y) diff --git a/skimage/rank/crank_percentiles.pyx b/skimage/rank/_crank8_percentiles.pyx similarity index 90% rename from skimage/rank/crank_percentiles.pyx rename to skimage/rank/_crank8_percentiles.pyx index d4d6312f..81730313 100644 --- a/skimage/rank/crank_percentiles.pyx +++ b/skimage/rank/_crank8_percentiles.pyx @@ -15,7 +15,7 @@ import numpy as np cimport numpy as np # import main loop -from core8p cimport rank8_percentile +from _core8p cimport _core8p # ----------------------------------------------------------------- # kernels uint8 (SOFT version using percentiles) @@ -189,7 +189,7 @@ def autolevel(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """bottom hat """ - return rank8_percentile(kernel_autolevel,image,selem,mask,out,shift_x,shift_y,p0,p1) + return _core8p(kernel_autolevel,image,selem,mask,out,shift_x,shift_y,p0,p1) def gradient(np.ndarray[np.uint8_t, ndim=2] image, @@ -199,7 +199,7 @@ def gradient(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return p0,p1 percentile gradient """ - return rank8_percentile(kernel_gradient,image,selem,mask,out,shift_x,shift_y,p0,p1) + return _core8p(kernel_gradient,image,selem,mask,out,shift_x,shift_y,p0,p1) def mean(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -208,7 +208,7 @@ def mean(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return mean between [p0 and p1] percentiles """ - return rank8_percentile(kernel_mean,image,selem,mask,out,shift_x,shift_y,p0,p1) + return _core8p(kernel_mean,image,selem,mask,out,shift_x,shift_y,p0,p1) def mean_substraction(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -217,7 +217,7 @@ def mean_substraction(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return original - mean between [p0 and p1] percentiles *.5 +127 """ - return rank8_percentile(kernel_mean_substraction,image,selem,mask,out,shift_x,shift_y,p0,p1) + return _core8p(kernel_mean_substraction,image,selem,mask,out,shift_x,shift_y,p0,p1) def morph_contr_enh(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -226,7 +226,7 @@ def morph_contr_enh(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """reforce contrast using percentiles """ - return rank8_percentile(kernel_morph_contr_enh,image,selem,mask,out,shift_x,shift_y,p0,p1) + return _core8p(kernel_morph_contr_enh,image,selem,mask,out,shift_x,shift_y,p0,p1) def percentile(np.ndarray[np.uint8_t, ndim=2] image, @@ -236,7 +236,7 @@ def percentile(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return p0 percentile """ - return rank8_percentile(kernel_percentile,image,selem,mask,out,shift_x,shift_y,p0,p1) + return _core8p(kernel_percentile,image,selem,mask,out,shift_x,shift_y,p0,p1) def pop(np.ndarray[np.uint8_t, ndim=2] image, @@ -246,7 +246,7 @@ def pop(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return nb of pixels between [p0 and p1] """ - return rank8_percentile(kernel_pop,image,selem,mask,out,shift_x,shift_y,p0,p1) + return _core8p(kernel_pop,image,selem,mask,out,shift_x,shift_y,p0,p1) def threshold(np.ndarray[np.uint8_t, ndim=2] image, np.ndarray[np.uint8_t, ndim=2] selem, @@ -255,4 +255,4 @@ def threshold(np.ndarray[np.uint8_t, ndim=2] image, char shift_x=0, char shift_y=0, float p0=0., float p1=0.): """return 255 if g > percentile p0 """ - return rank8_percentile(kernel_threshold,image,selem,mask,out,shift_x,shift_y,p0,p1) + return _core8p(kernel_threshold,image,selem,mask,out,shift_x,shift_y,p0,p1) diff --git a/skimage/rank/cmorph.pyx b/skimage/rank/cmorph.pyx deleted file mode 100644 index 9b8b3a27..00000000 --- a/skimage/rank/cmorph.pyx +++ /dev/null @@ -1,118 +0,0 @@ -#cython: cdivision=True -#cython: boundscheck=False -#cython: nonecheck=False -#cython: wraparound=False - -import numpy as np -cimport numpy as np -from libc.stdlib cimport malloc, free - - -def dilate(np.ndarray[np.uint8_t, ndim=2] image, - np.ndarray[np.uint8_t, ndim=2] selem, - np.ndarray[np.uint8_t, ndim=2] out=None, - char shift_x=0, char shift_y=0): - - cdef int rows = image.shape[0] - cdef int cols = image.shape[1] - cdef int srows = selem.shape[0] - cdef int scols = selem.shape[1] - - cdef int centre_r = int(selem.shape[0] / 2) - shift_y - cdef int centre_c = int(selem.shape[1] / 2) - shift_x - - image = np.ascontiguousarray(image) - if out is None: - out = np.zeros((rows, cols), dtype=np.uint8) - else: - out = np.ascontiguousarray(out) - - cdef np.uint8_t* out_data = out.data - cdef np.uint8_t* image_data = image.data - - cdef int r, c, rr, cc, s, value, local_max - - cdef int selem_num = np.sum(selem != 0) - cdef int* sr = malloc(selem_num * sizeof(int)) - cdef int* sc = malloc(selem_num * sizeof(int)) - - s = 0 - for r in range(srows): - for c in range(scols): - if selem[r, c] != 0: - sr[s] = r - centre_r - sc[s] = c - centre_c - s += 1 - - for r in range(rows): - for c in range(cols): - local_max = 0 - for s in range(selem_num): - rr = r + sr[s] - cc = c + sc[s] - if 0 <= rr < rows and 0 <= cc < cols: - value = image_data[rr * cols + cc] - if value > local_max: - local_max = value - - out_data[r * cols + c] = local_max - - free(sr) - free(sc) - - return out - - -def erode(np.ndarray[np.uint8_t, ndim=2] image, - np.ndarray[np.uint8_t, ndim=2] selem, - np.ndarray[np.uint8_t, ndim=2] out=None, - char shift_x=0, char shift_y=0): - - cdef int rows = image.shape[0] - cdef int cols = image.shape[1] - cdef int srows = selem.shape[0] - cdef int scols = selem.shape[1] - - cdef int centre_r = int(selem.shape[0] / 2) - shift_y - cdef int centre_c = int(selem.shape[1] / 2) - shift_x - - image = np.ascontiguousarray(image) - if out is None: - out = np.zeros((rows, cols), dtype=np.uint8) - else: - out = np.ascontiguousarray(out) - - cdef np.uint8_t* out_data = out.data - cdef np.uint8_t* image_data = image.data - - cdef int r, c, rr, cc, s, value, local_min - - cdef int selem_num = np.sum(selem != 0) - cdef int* sr = malloc(selem_num * sizeof(int)) - cdef int* sc = malloc(selem_num * sizeof(int)) - - s = 0 - for r in range(srows): - for c in range(scols): - if selem[r, c] != 0: - sr[s] = r - centre_r - sc[s] = c - centre_c - s += 1 - - for r in range(rows): - for c in range(cols): - local_min = 255 - for s in range(selem_num): - rr = r + sr[s] - cc = c + sc[s] - if 0 <= rr < rows and 0 <= cc < cols: - value = image_data[rr * cols + cc] - if value < local_min: - local_min = value - - out_data[r * cols + c] = local_min - - free(sr) - free(sc) - - return out diff --git a/skimage/rank/setup.py b/skimage/rank/setup.py index 8c5a595a..e8b2691d 100644 --- a/skimage/rank/setup.py +++ b/skimage/rank/setup.py @@ -6,13 +6,45 @@ from Cython.Distutils import build_ext setup( cmdclass = {'build_ext': build_ext}, - ext_modules = [Extension("cmorph", ["cmorph.pyx"], include_dirs=[np.get_include()]), - Extension("crank", ["crank.pyx"], include_dirs=[np.get_include()]), - Extension("crank_percentiles", ["crank_percentiles.pyx"], include_dirs=[np.get_include()]), - Extension("crank16", ["crank16.pyx"], include_dirs=[np.get_include()]), - Extension("crank16_bilateral", ["crank16_bilateral.pyx"], include_dirs=[np.get_include()]), - Extension("crank16_percentiles", ["crank16_percentiles.pyx"], include_dirs=[np.get_include()])] + ext_modules = [Extension("crank8", ["_crank8.pyx"], include_dirs=[np.get_include()]), + Extension("crank8_percentiles", ["_crank8_percentiles.pyx"], include_dirs=[np.get_include()]), + Extension("crank16", ["_crank16.pyx"], include_dirs=[np.get_include()]), + Extension("crank16_bilateral", ["_crank16_bilateral.pyx"], include_dirs=[np.get_include()]), + Extension("crank16_percentiles", ["_crank16_percentiles.pyx"], include_dirs=[np.get_include()])] ) - +##!/usr/bin/env python +# +#import os +#from skimage._build import cython +# +#base_path = os.path.abspath(os.path.dirname(__file__)) +# +# +#def configuration(parent_package='', top_path=None): +# from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs +# +# config = Configuration('rank', parent_package, top_path) +# config.add_data_dir('tests') +# +# cython(['_texture.pyx'], working_path=base_path) +# cython(['_template.pyx'], working_path=base_path) +# +# config.add_extension('_texture', sources=['_texture.c'], +# include_dirs=[get_numpy_include_dirs(), '../_shared']) +# config.add_extension('_template', sources=['_template.c'], +# include_dirs=[get_numpy_include_dirs(), '../_shared']) +# +# return config +# +#if __name__ == '__main__': +# from numpy.distutils.core import setup +# setup(maintainer='scikits-image Developers', +# author='scikits-image Developers', +# maintainer_email='scikits-image@googlegroups.com', +# description='Features', +# url='https://github.com/scikits-image/scikits-image', +# license='SciPy License (BSD Style)', +# **(configuration(top_path='').todict()) +# ) diff --git a/skimage/rank/tests/test_16bitbilateral.py b/skimage/rank/tests/test_16bitbilateral.py index ac078b09..98d76573 100644 --- a/skimage/rank/tests/test_16bitbilateral.py +++ b/skimage/rank/tests/test_16bitbilateral.py @@ -2,14 +2,14 @@ import numpy as np import matplotlib.pyplot as plt from skimage import data -from skimage.rank import crank_percentiles,crank16_bilateral +from skimage.rank import crank8_percentiles,crank16_bilateral if __name__ == '__main__': a8 = (data.coins()).astype('uint8') a16 = (data.coins()).astype('uint16')*16 selem = np.ones((20,20),dtype='uint8') - f1 = crank_percentiles.mean(a8,selem = selem,p0=.1,p1=.9) + f1 = crank8_percentiles.mean(a8,selem = selem,p0=.1,p1=.9) f2 = crank16_bilateral.mean(a16,selem = selem,bitdepth=12,s0=500,s1=500) plt.figure() diff --git a/skimage/rank/tests/test_benchmark.py b/skimage/rank/tests/test_benchmark.py index 4fee48c1..c67742e3 100644 --- a/skimage/rank/tests/test_benchmark.py +++ b/skimage/rank/tests/test_benchmark.py @@ -3,13 +3,13 @@ import matplotlib.pyplot as plt from skimage import data from skimage.morphology import cmorph -from skimage.rank import crank +from skimage.rank import crank8 from tools import log_timing @log_timing def cr_max(image,selem): - return crank.maximum(image=image,selem = selem) + return crank8.maximum(image=image,selem = selem) @log_timing def cm_dil(image,selem): diff --git a/skimage/rank/tests/test_suite.py b/skimage/rank/tests/test_suite.py index 61ceab48..0dcb21ab 100644 --- a/skimage/rank/tests/test_suite.py +++ b/skimage/rank/tests/test_suite.py @@ -2,7 +2,8 @@ import unittest import numpy as np -from skimage.rank import crank,crank16,crank16_bilateral,crank16_percentiles,crank_percentiles +from skimage.rank import crank8,crank8_percentiles +from skimage.rank import crank16,crank16_bilateral,crank16_percentiles from skimage.morphology import cmorph class TestSequenceFunctions(unittest.TestCase): @@ -16,9 +17,9 @@ class TestSequenceFunctions(unittest.TestCase): elem = np.asarray([[1,1,1],[1,1,1],[1,1,1]],dtype='uint8') for m,n in np.random.random_integers(1,100,size=(10,2)): a8 = np.ones((m,n),dtype='uint8') - r = crank.mean(image=a8,selem = elem,shift_x=0,shift_y=0) + r = crank8.mean(image=a8,selem = elem,shift_x=0,shift_y=0) self.assertTrue(a8.shape == r.shape) - r = crank.mean(image=a8,selem = elem,shift_x=+1,shift_y=+1) + r = crank8.mean(image=a8,selem = elem,shift_x=+1,shift_y=+1) self.assertTrue(a8.shape == r.shape) for m,n in np.random.random_integers(1,100,size=(10,2)): @@ -42,7 +43,7 @@ class TestSequenceFunctions(unittest.TestCase): for r in range(1,20,1): elem = np.ones((r,r),dtype='uint8') # elem = (np.random.random((r,r))>.5).astype('uint8') - rc = crank.maximum(image=a,selem = elem) + rc = crank8.maximum(image=a,selem = elem) cm = cmorph.dilate(image=a,selem = elem) self.assertTrue((rc==cm).all()) @@ -62,7 +63,7 @@ class TestSequenceFunctions(unittest.TestCase): def test_population(self): a = np.zeros((5,5),dtype='uint8') elem = np.ones((3,3),dtype='uint8') - p = crank.pop(image=a,selem = elem) + p = crank8.pop(image=a,selem = elem) r = np.asarray([[4, 6, 6, 6, 4], [6, 9, 9, 9, 6], [6, 9, 9, 9, 6], @@ -74,7 +75,7 @@ class TestSequenceFunctions(unittest.TestCase): a = np.zeros((6,6),dtype='uint8') a[2,2] = 255 elem = np.asarray([[1,1,0],[1,1,1],[0,0,1]],dtype='uint8') - f = crank.maximum(image=a,selem = elem,shift_x=1,shift_y=1) + f = crank8.maximum(image=a,selem = elem,shift_x=1,shift_y=1) r = np.asarray([[ 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0], [ 0, 0, 255, 0, 0, 0],