mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-30 23:11:53 +08:00
adapt tests
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
To use this to build your Cython file use the commandline options:
|
||||
|
||||
.. sourcecode:: text
|
||||
|
||||
$ python setup.py build_ext --inplace
|
||||
|
||||
|
||||
**To do**
|
||||
|
||||
* add simple examples
|
||||
|
||||
* add doc
|
||||
* add/check existing doc
|
||||
|
||||
|
||||
|
||||
.. sourcecode:: text
|
||||
|
||||
$ python setup.py build_ext --inplace
|
||||
@@ -13,7 +13,7 @@ from generic import find_bitdepth
|
||||
import _crank16,_crank8
|
||||
|
||||
__all__ = ['autolevel','bottomhat','egalise','gradient','maximum','mean'
|
||||
,'meansubstraction','median','minimum','modal','morph_contr_enh','pop']
|
||||
,'meansubstraction','median','minimum','modal','morph_contr_enh','pop','threshold', 'tophat']
|
||||
|
||||
def autolevel(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
|
||||
"""Return greyscale local autolevel of an image.
|
||||
|
||||
@@ -2,16 +2,19 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage.rank import crank8_percentiles
|
||||
from skimage.rank import crank16_bilateral
|
||||
from skimage.morphology import disk
|
||||
import skimage.rank as rank
|
||||
|
||||
if __name__ == '__main__':
|
||||
a8 = (data.coins()).astype('uint8')
|
||||
|
||||
a16 = (data.coins()).astype('uint16')*16
|
||||
selem = np.ones((20,20),dtype='uint8')
|
||||
f1 = crank8_percentiles.mean(a8,selem = selem,p0=.1,p1=.9)
|
||||
f2 = crank16_bilateral.mean(a16,selem = selem,bitdepth=12,s0=500,s1=500)
|
||||
f1 = rank.percentile_mean(a8,selem = selem,p0=.1,p1=.9)
|
||||
f2 = rank.bilateral_mean(a16,selem = selem,s0=500,s1=500)
|
||||
|
||||
selem = disk(50)
|
||||
f3 = rank.egalise(a16,selem = selem)
|
||||
|
||||
plt.figure()
|
||||
plt.imshow(np.hstack((a8,f1)))
|
||||
@@ -21,4 +24,8 @@ if __name__ == '__main__':
|
||||
plt.imshow(np.hstack((a16,f2)))
|
||||
plt.colorbar()
|
||||
|
||||
plt.figure()
|
||||
plt.imshow(np.hstack((a16,f3)))
|
||||
plt.colorbar()
|
||||
|
||||
plt.show()
|
||||
|
||||
@@ -3,13 +3,13 @@ import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage.morphology import dilation
|
||||
from skimage.rank import _crank8
|
||||
import skimage.rank as rank
|
||||
|
||||
from tools import log_timing
|
||||
|
||||
@log_timing
|
||||
def cr_max(image,selem):
|
||||
return _crank8.maximum(image=image,selem = selem)
|
||||
return rank.maximum(image=image,selem = selem)
|
||||
|
||||
@log_timing
|
||||
def cm_dil(image,selem):
|
||||
|
||||
@@ -2,8 +2,8 @@ import unittest
|
||||
|
||||
import numpy as np
|
||||
|
||||
from skimage.rank import crank8,crank8_percentiles
|
||||
from skimage.rank import crank16,crank16_bilateral,crank16_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):
|
||||
@@ -17,23 +17,23 @@ 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 = crank8.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 = crank8.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)):
|
||||
a16 = np.ones((m,n),dtype='uint16')
|
||||
r = crank16.mean(image=a16,selem = elem,shift_x=0,shift_y=0)
|
||||
r = _crank16.mean(image=a16,selem = elem,shift_x=0,shift_y=0)
|
||||
self.assertTrue(a16.shape == r.shape)
|
||||
r = crank16.mean(image=a16,selem = elem,shift_x=+1,shift_y=+1)
|
||||
r = _crank16.mean(image=a16,selem = elem,shift_x=+1,shift_y=+1)
|
||||
self.assertTrue(a16.shape == r.shape)
|
||||
|
||||
for m,n in np.random.random_integers(1,100,size=(10,2)):
|
||||
a16 = np.ones((m,n),dtype='uint16')
|
||||
r = crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9)
|
||||
r = _crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9)
|
||||
self.assertTrue(a16.shape == r.shape)
|
||||
r = crank16_percentiles.mean(image=a16,selem = elem,shift_x=+1,shift_y=+1,p0=.1,p1=.9)
|
||||
r = _crank16_percentiles.mean(image=a16,selem = elem,shift_x=+1,shift_y=+1,p0=.1,p1=.9)
|
||||
self.assertTrue(a16.shape == r.shape)
|
||||
|
||||
def test_compare_with_cmorph(self):
|
||||
@@ -43,27 +43,27 @@ 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 = crank8.maximum(image=a,selem = elem)
|
||||
rc = _crank8.maximum(image=a,selem = elem)
|
||||
cm = cmorph.dilate(image=a,selem = elem)
|
||||
self.assertTrue((rc==cm).all())
|
||||
|
||||
def test_bitdepth(self):
|
||||
elem = np.ones((3,3),dtype='uint8')
|
||||
a16 = np.ones((100,100),dtype='uint16')*255
|
||||
r = crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=8)
|
||||
r = _crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=8)
|
||||
a16 = np.ones((100,100),dtype='uint16')*255*2
|
||||
r = crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=9)
|
||||
r = _crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=9)
|
||||
a16 = np.ones((100,100),dtype='uint16')*255*4
|
||||
r = crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=10)
|
||||
r = _crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=10)
|
||||
a16 = np.ones((100,100),dtype='uint16')*255*8
|
||||
r = crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=11)
|
||||
r = _crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=11)
|
||||
a16 = np.ones((100,100),dtype='uint16')*255*16
|
||||
r = crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=12)
|
||||
r = _crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=12)
|
||||
|
||||
def test_population(self):
|
||||
a = np.zeros((5,5),dtype='uint8')
|
||||
elem = np.ones((3,3),dtype='uint8')
|
||||
p = crank8.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],
|
||||
@@ -75,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 = crank8.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],
|
||||
@@ -90,7 +90,7 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
# should fail because data bitdepth is too high for the function
|
||||
a16 = np.ones((100,100),dtype='uint16')*255
|
||||
elem = np.ones((3,3),dtype='uint8')
|
||||
f = crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=4)
|
||||
f = _crank16_percentiles.mean(image=a16,selem = elem,shift_x=0,shift_y=0,p0=.1,p1=.9,bitdepth=4)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
|
||||
Reference in New Issue
Block a user