From 42feb70a31cf0ef6f9cf23b82f6b44bf424a67e6 Mon Sep 17 00:00:00 2001 From: Olivier Debeir Date: Thu, 11 Oct 2012 12:03:34 +0200 Subject: [PATCH] add exhaustive comparison between 8bit and 16bit filters --- skimage/rank/rank.py | 6 +++++- skimage/rank/tests/test_suite.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/skimage/rank/rank.py b/skimage/rank/rank.py index 5dfa85bc..bc7dadff 100644 --- a/skimage/rank/rank.py +++ b/skimage/rank/rank.py @@ -1019,4 +1019,8 @@ def tophat(image, selem, out=None, mask=None, shift_x=False, shift_y=False): raise ValueError("only uint16 <4096 image (12bit) supported!") return _crank16.tophat(image,selem,shift_x=shift_x,shift_y=shift_y,mask=mask,bitdepth=bitdepth+1,out=out) else: - raise TypeError("only uint8 and uint16 image supported!") \ No newline at end of file + raise TypeError("only uint8 and uint16 image supported!") + +if __name__ == "__main__": + import doctest + doctest.testmod(verbose=True) \ No newline at end of file diff --git a/skimage/rank/tests/test_suite.py b/skimage/rank/tests/test_suite.py index 5d47138b..97345f4f 100644 --- a/skimage/rank/tests/test_suite.py +++ b/skimage/rank/tests/test_suite.py @@ -104,6 +104,25 @@ class TestSequenceFunctions(unittest.TestCase): assert (loc_autolevel==loc_perc_autolevel).all() + def test_compare_8bit_vs_16bit(self): + # filters applied on 8bit image ore 16bit image (having only real 8bit of dynamic) should be identical + i8 = data.camera() + i16 = i8.astype(np.uint16) + methods = ['autolevel','bottomhat','equalize','gradient','maximum','mean' + ,'meansubstraction','median','minimum','modal','morph_contr_enh','pop','threshold', 'tophat'] + for method in methods: + func = eval('rank.%s'%method) + print func + f8 = func(i8,disk(3)) + f16 = func(i16,disk(3)) +# if (f8==f16).all() is False: + if not (f8==f16).all(): + + print f8 + print f16 + + + if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)