diff --git a/skimage/rank/__init__.py b/skimage/rank/__init__.py index bcc43cdc..8b0e3f5b 100644 --- a/skimage/rank/__init__.py +++ b/skimage/rank/__init__.py @@ -1 +1 @@ -from .rank import * +from .crank import * diff --git a/skimage/rank/core.pxd b/skimage/rank/core.pxd index 72facde3..bb57aec4 100644 --- a/skimage/rank/core.pxd +++ b/skimage/rank/core.pxd @@ -18,7 +18,6 @@ from libc.stdlib cimport malloc, free cdef inline int int_max(int a, int b): return a if a >= b else b cdef inline int int_min(int a, int b): return a if a <= b else b - #--------------------------------------------------------------------------- # 8 bit core kernel #--------------------------------------------------------------------------- diff --git a/skimage/rank/test/test_16bitbilateral.py b/skimage/rank/test/test_16bitbilateral.py new file mode 100644 index 00000000..ac078b09 --- /dev/null +++ b/skimage/rank/test/test_16bitbilateral.py @@ -0,0 +1,23 @@ +import numpy as np +import matplotlib.pyplot as plt + +from skimage import data +from skimage.rank import crank_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) + f2 = crank16_bilateral.mean(a16,selem = selem,bitdepth=12,s0=500,s1=500) + + plt.figure() + plt.imshow(np.hstack((a8,f1))) + plt.colorbar() + + plt.figure() + plt.imshow(np.hstack((a16,f2))) + plt.colorbar() + + plt.show() diff --git a/skimage/rank/test/test_benchmark.py b/skimage/rank/test/test_benchmark.py new file mode 100644 index 00000000..4fee48c1 --- /dev/null +++ b/skimage/rank/test/test_benchmark.py @@ -0,0 +1,72 @@ +import numpy as np +import matplotlib.pyplot as plt + +from skimage import data +from skimage.morphology import cmorph +from skimage.rank import crank + +from tools import log_timing + +@log_timing +def cr_max(image,selem): + return crank.maximum(image=image,selem = selem) + +@log_timing +def cm_dil(image,selem): + return cmorph.dilate(image=image,selem = selem) + + +def compare(): + """comparison between + - crank.maximum rankfilter implementation + - cmorph.dilate cython implementation + on increasing structuring element size and increasing image size + """ +# a = (np.random.random((500,500))*256).astype('uint8') + a = data.camera() + + rec = [] + e_range = range(1,20,1) + for r in e_range: + elem = np.ones((r,r),dtype='uint8') + # elem = (np.random.random((r,r))>.5).astype('uint8') + rc,ms_rc = cr_max(a,elem) + rcm,ms_rcm = cm_dil(a,elem) + rec.append((ms_rc,ms_rcm)) + # check if results are identical + assert (rc==rcm).all() + + rec = np.asarray(rec) + + plt.figure() + plt.title('increasing element size') + plt.plot(e_range,rec) + plt.legend(['crank.maximum','cmorph.dilate']) + plt.figure() + plt.imshow(np.hstack((rc,rcm))) + + r = 9 + elem = np.ones((r,r),dtype='uint8') + + rec = [] + s_range = range(100,1000,100) + for s in s_range: + a = (np.random.random((s,s))*256).astype('uint8') + (rc,ms_rc) = cr_max(a,elem) + (rcm,ms_rcm) = cm_dil(a,elem) + rec.append((ms_rc,ms_rcm)) + assert (rc==rcm).all() + + rec = np.asarray(rec) + + plt.figure() + plt.title('increasing image size') + plt.plot(s_range,rec) + plt.legend(['crank.maximum','cmorph.dilate']) + plt.figure() + plt.imshow(np.hstack((rc,rcm))) + + plt.show() + +if __name__ == '__main__': + compare() \ No newline at end of file diff --git a/skimage/rank/app.py b/skimage/rank/test/test_suite.py similarity index 59% rename from skimage/rank/app.py rename to skimage/rank/test/test_suite.py index 0cf24408..61ceab48 100644 --- a/skimage/rank/app.py +++ b/skimage/rank/test/test_suite.py @@ -1,73 +1,10 @@ import unittest import numpy as np -from time import time -import matplotlib.pyplot as plt -from skimage import data -from tools import log_timing,init_logger +from skimage.rank import crank,crank16,crank16_bilateral,crank16_percentiles,crank_percentiles +from skimage.morphology import cmorph -import crank -import crank16 -import crank_percentiles -import crank16_percentiles -import crank16_bilateral -from cmorph import dilate - - -@log_timing -def c_max(image,selem): - return crank.maximum(image=image,selem = selem) - -@log_timing -def cm_max(image,selem): - return dilate(image=image,selem = selem) - -def compare(): - """comparison between - - Cython maximum rankfilter implementation - - weaves maximum rankfilter implementation - - cmorph.dilate cython implementation - on increasing structuring element size and increasing image size - """ - a = (np.random.random((500,500))*256).astype('uint8') - - rec = [] - for r in range(1,20,1): - elem = np.ones((r,r),dtype='uint8') - # elem = (np.random.random((r,r))>.5).astype('uint8') - (rc,ms_rc) = c_max(a,elem) - (rcm,ms_rcm) = cm_max(a,elem) - rec.append((ms_rc,ms_rw,ms_rcm)) - assert (rc==rcm).all() - - rec = np.asarray(rec) - - plt.plot(rec) - plt.legend(['sliding cython','sliding weaves','cmorph']) - plt.figure() - plt.imshow(np.hstack((rc,rw,rcm))) - - r = 9 - elem = np.ones((r,r),dtype='uint8') - - rec = [] - for s in range(100,1000,100): - a = (np.random.random((s,s))*256).astype('uint8') - (rc,ms_rc) = c_max(a,elem) - (rcm,ms_rcm) = cm_max(a,elem) - rec.append((ms_rc,ms_rw,ms_rcm)) - assert (rc==rcm).all() - - rec = np.asarray(rec) - - plt.figure() - plt.plot(rec) - plt.legend(['sliding cython','sliding weaves','cmorph']) - plt.figure() - plt.imshow(np.hstack((rc,rcm))) - - plt.show() class TestSequenceFunctions(unittest.TestCase): def setUp(self): @@ -106,7 +43,7 @@ class TestSequenceFunctions(unittest.TestCase): elem = np.ones((r,r),dtype='uint8') # elem = (np.random.random((r,r))>.5).astype('uint8') rc = crank.maximum(image=a,selem = elem) - cm = dilate(image=a,selem = elem) + cm = cmorph.dilate(image=a,selem = elem) self.assertTrue((rc==cm).all()) def test_bitdepth(self): @@ -139,11 +76,11 @@ class TestSequenceFunctions(unittest.TestCase): 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) r = np.asarray([[ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 255, 0, 0, 0], - [ 0, 0, 255, 255, 255, 0], - [ 0, 0, 0, 255, 255, 0], - [ 0, 0, 0, 0, 0, 0]]) + [ 0, 0, 0, 0, 0, 0], + [ 0, 0, 255, 0, 0, 0], + [ 0, 0, 255, 255, 255, 0], + [ 0, 0, 0, 255, 255, 0], + [ 0, 0, 0, 0, 0, 0]]) np.testing.assert_array_equal(r,f) @@ -156,27 +93,5 @@ class TestSequenceFunctions(unittest.TestCase): if __name__ == '__main__': - logger = init_logger('app.log') - -# unittest.main() suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions) unittest.TextTestRunner(verbosity=2).run(suite) - - -# compare() - -# a = (data.coins()).astype('uint8') - a8 = (data.coins()).astype('uint8') - a = (data.coins()).astype('uint16')*16 - selem = np.ones((20,20),dtype='uint8') -# f1 = filter.soft_gradient(a,struct_elem = selem,bitDepth=8,infSup=[.1,.9]) -# f2 = crank16.bottomhat(a,selem = selem,bitdepth=12) - f1 = crank_percentiles.mean(a8,selem = selem,p0=.1,p1=.9) -# f2 = crank16_percentiles.mean(a,selem = selem,bitdepth=12,p0=.1,p1=.9) - f2 = crank16_bilateral.mean(a,selem = selem,bitdepth=12,s0=500,s1=500) -# plt.imshow(f2) - plt.imshow(np.hstack((a,f2))) - plt.colorbar() - plt.show() - - diff --git a/skimage/rank/tools.py b/skimage/rank/test/tools.py similarity index 78% rename from skimage/rank/tools.py rename to skimage/rank/test/tools.py index 835a8884..2fba4798 100644 --- a/skimage/rank/tools.py +++ b/skimage/rank/test/tools.py @@ -39,14 +39,4 @@ def log_timing(func): log_timing.level = 0 -def tumbnail_it(data): - """display image with its histogram - """ - h = np.histogram(data[:],100) - hn = 512*h[0]/np.max(h[0]) - plt.subplot(1,2,1) - plt.imshow(ima8,interpolation='nearest',cmap=cm.gray) - plt.subplot(1,2,2) - plt.plot(hn) - plt.colorbar()