From 29a2fc3c22d310f2514037664f3cb4e805d2d167 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Mon, 19 Dec 2011 23:25:32 -0500 Subject: [PATCH 1/8] Remove unused imports --- skimage/morphology/tests/test_morphology.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/skimage/morphology/tests/test_morphology.py b/skimage/morphology/tests/test_morphology.py index 2d089c58..113f0356 100644 --- a/skimage/morphology/tests/test_morphology.py +++ b/skimage/morphology/tests/test_morphology.py @@ -1,10 +1,8 @@ import os.path import numpy as np -from numpy.testing import * +from numpy.testing import assert_equal -from skimage import data_dir -from skimage.io import imread from skimage import data_dir from skimage.morphology import * From cfa9bbfc40a846ddbcc3f0507c02f1e4841bd21a Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 20 Dec 2011 19:28:26 -0800 Subject: [PATCH 2/8] Rename greyscale morphology functions. Remove "greyscale" prefix on functions in ``morphology.grey``. To avoid confusion (and name clashes), ``greyscale_open`` and ``greyscale_close`` were renamed ``opening`` and ``closing`` (instead of ``open`` and ``close``). As a bonus, these names match scipy.ndimage. --- skimage/morphology/grey.py | 67 +++++++++++++++------ skimage/morphology/tests/test_morphology.py | 48 ++++++++------- 2 files changed, 72 insertions(+), 43 deletions(-) diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index c82e2585..851c0c87 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -5,11 +5,15 @@ __docformat__ = 'restructuredtext en' +import warnings + import numpy as np + eps = np.finfo(float).eps -def greyscale_erode(image, selem, out=None, shift_x=False, shift_y=False): + +def erosion(image, selem, out=None, shift_x=False, shift_y=False): """Return greyscale morphological erosion of an image. Morphological erosion sets a pixel at (i,j) to the minimum over all pixels @@ -46,7 +50,7 @@ def greyscale_erode(image, selem, out=None, shift_x=False, shift_y=False): ... [0, 1, 1, 1, 0], ... [0, 1, 1, 1, 0], ... [0, 0, 0, 0, 0]], dtype=np.uint8) - >>> greyscale_erode(bright_square, square(3)) + >>> erosion(bright_square, square(3)) array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], @@ -64,7 +68,7 @@ def greyscale_erode(image, selem, out=None, shift_x=False, shift_y=False): except ImportError: raise ImportError("cmorph extension not available.") -def greyscale_dilate(image, selem, out=None, shift_x=False, shift_y=False): +def dilation(image, selem, out=None, shift_x=False, shift_y=False): """Return greyscale morphological dilation of an image. Morphological dilation sets a pixel at (i,j) to the maximum over all pixels @@ -102,7 +106,7 @@ def greyscale_dilate(image, selem, out=None, shift_x=False, shift_y=False): ... [0, 0, 1, 0, 0], ... [0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0]], dtype=np.uint8) - >>> greyscale_dilate(bright_pixel, square(3)) + >>> dilation(bright_pixel, square(3)) array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], @@ -120,7 +124,7 @@ def greyscale_dilate(image, selem, out=None, shift_x=False, shift_y=False): except ImportError: raise ImportError("cmorph extension not available.") -def greyscale_open(image, selem, out=None): +def opening(image, selem, out=None): """Return greyscale morphological opening of an image. The morphological opening on an image is defined as an erosion followed by @@ -154,7 +158,7 @@ def greyscale_open(image, selem, out=None): ... [1, 1, 1, 1, 1], ... [1, 1, 0, 1, 1], ... [1, 0, 0, 0, 1]], dtype=np.uint8) - >>> greyscale_open(bad_connection, square(3)) + >>> opening(bad_connection, square(3)) array([[0, 0, 0, 0, 0], [1, 1, 0, 1, 1], [1, 1, 0, 1, 1], @@ -166,12 +170,11 @@ def greyscale_open(image, selem, out=None): shift_x = True if (w % 2) == 0 else False shift_y = True if (h % 2) == 0 else False - eroded = greyscale_erode(image, selem) - out = greyscale_dilate(eroded, selem, out=out, - shift_x=shift_x, shift_y=shift_y) + eroded = erosion(image, selem) + out = dilation(eroded, selem, out=out, shift_x=shift_x, shift_y=shift_y) return out -def greyscale_close(image, selem, out=None): +def closing(image, selem, out=None): """Return greyscale morphological closing of an image. The morphological closing on an image is defined as a dilation followed by @@ -205,7 +208,7 @@ def greyscale_close(image, selem, out=None): ... [1, 1, 0, 1, 1], ... [0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0]], dtype=np.uint8) - >>> greyscale_close(broken_line, square(3)) + >>> closing(broken_line, square(3)) array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], @@ -217,12 +220,11 @@ def greyscale_close(image, selem, out=None): shift_x = True if (w % 2) == 0 else False shift_y = True if (h % 2) == 0 else False - dilated = greyscale_dilate(image, selem) - out = greyscale_erode(dilated, selem, out=out, - shift_x=shift_x, shift_y=shift_y) + dilated = dilation(image, selem) + out = erosion(dilated, selem, out=out, shift_x=shift_x, shift_y=shift_y) return out -def greyscale_white_top_hat(image, selem, out=None): +def white_tophat(image, selem, out=None): """Return white top hat of an image. The white top hat of an image is defined as the image minus its @@ -255,7 +257,7 @@ def greyscale_white_top_hat(image, selem, out=None): ... [3, 5, 9, 5, 3], ... [3, 4, 5, 4, 3], ... [2, 3, 3, 3, 2]], dtype=np.uint8) - >>> greyscale_white_top_hat(bright_on_grey, square(3)) + >>> white_tophat(bright_on_grey, square(3)) array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 5, 1, 0], @@ -266,11 +268,11 @@ def greyscale_white_top_hat(image, selem, out=None): if image is out: raise NotImplementedError("Cannot perform white top hat in place.") - out = greyscale_open(image, selem, out=out) + out = opening(image, selem, out=out) out = image - out return out -def greyscale_black_top_hat(image, selem, out=None): +def black_tophat(image, selem, out=None): """Return black top hat of an image. The black top hat of an image is defined as its morphological closing minus @@ -304,7 +306,7 @@ def greyscale_black_top_hat(image, selem, out=None): ... [6, 4, 0, 4, 6], ... [6, 5, 4, 5, 6], ... [7, 6, 6, 6, 7]], dtype=np.uint8) - >>> greyscale_black_top_hat(dark_on_grey, square(3)) + >>> black_tophat(dark_on_grey, square(3)) array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 5, 1, 0], @@ -314,7 +316,32 @@ def greyscale_black_top_hat(image, selem, out=None): """ if image is out: raise NotImplementedError("Cannot perform white top hat in place.") - out = greyscale_close(image, selem, out=out) + out = closing(image, selem, out=out) out = out - image return out + +def greyscale_erode(*args, **kwargs): + warnings.warn("`greyscale_erode` renamed `erosion`.") + return erosion(*args, **kwargs) + +def greyscale_dilate(*args, **kwargs): + warnings.warn("`greyscale_dilate` renamed `dilation`.") + return dilation(*args, **kwargs) + +def greyscale_open(*args, **kwargs): + warnings.warn("`greyscale_open` renamed `opening`.") + return opening(*args, **kwargs) + +def greyscale_close(*args, **kwargs): + warnings.warn("`greyscale_close` renamed `closing`.") + return closing(*args, **kwargs) + +def greyscale_white_top_hat(*args, **kwargs): + warnings.warn("`greyscale_white_top_hat` renamed `white_tophat`.") + return white_tophat(*args, **kwargs) + +def greyscale_black_top_hat(*args, **kwargs): + warnings.warn("`greyscale_black_top_hat` renamed `black_tophat`.") + return black_tophat(*args, **kwargs) + diff --git a/skimage/morphology/tests/test_morphology.py b/skimage/morphology/tests/test_morphology.py index 113f0356..320c775d 100644 --- a/skimage/morphology/tests/test_morphology.py +++ b/skimage/morphology/tests/test_morphology.py @@ -4,7 +4,9 @@ import numpy as np from numpy.testing import assert_equal from skimage import data_dir -from skimage.morphology import * +from skimage.morphology.grey import * +from skimage.morphology import selem + lena = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy')) @@ -22,43 +24,43 @@ class TestMorphology(): def test_erode_diamond(self): self.morph_worker(lena, "diamond-erode-matlab-output.npz", - greyscale_erode, diamond) + erosion, selem.diamond) def test_dilate_diamond(self): self.morph_worker(lena, "diamond-dilate-matlab-output.npz", - greyscale_dilate, diamond) + dilation, selem.diamond) def test_open_diamond(self): self.morph_worker(lena, "diamond-open-matlab-output.npz", - greyscale_open, diamond) + opening, selem.diamond) def test_close_diamond(self): self.morph_worker(lena, "diamond-close-matlab-output.npz", - greyscale_close, diamond) + closing, selem.diamond) def test_tophat_diamond(self): self.morph_worker(lena, "diamond-tophat-matlab-output.npz", - greyscale_white_top_hat, diamond) + white_tophat, selem.diamond) def test_bothat_diamond(self): self.morph_worker(lena, "diamond-bothat-matlab-output.npz", - greyscale_black_top_hat, diamond) + black_tophat, selem.diamond) def test_erode_disk(self): self.morph_worker(lena, "disk-erode-matlab-output.npz", - greyscale_erode, disk) + erosion, selem.disk) def test_dilate_disk(self): self.morph_worker(lena, "disk-dilate-matlab-output.npz", - greyscale_dilate, disk) + dilation, selem.disk) def test_open_disk(self): self.morph_worker(lena, "disk-open-matlab-output.npz", - greyscale_open, disk) + opening, selem.disk) def test_close_disk(self): self.morph_worker(lena, "disk-close-matlab-output.npz", - greyscale_close, disk) + closing, selem.disk) class TestEccentricStructuringElements(): @@ -67,50 +69,50 @@ class TestEccentricStructuringElements(): self.black_pixel = 255 * np.ones((4, 4), dtype=np.uint8) self.black_pixel[1, 1] = 0 self.white_pixel = 255 - self.black_pixel - self.selems = [square(2), rectangle(2, 2), - rectangle(2, 1), rectangle(1, 2)] + self.selems = [selem.square(2), selem.rectangle(2, 2), + selem.rectangle(2, 1), selem.rectangle(1, 2)] def test_dilate_erode_symmetry(self): for s in self.selems: - c = greyscale_erode(self.black_pixel, s) - d = greyscale_dilate(self.white_pixel, s) + c = erosion(self.black_pixel, s) + d = dilation(self.white_pixel, s) assert np.all(c == (255 - d)) def test_open_black_pixel(self): for s in self.selems: - grey_open = greyscale_open(self.black_pixel, s) + grey_open = opening(self.black_pixel, s) assert np.all(grey_open == self.black_pixel) def test_close_white_pixel(self): for s in self.selems: - grey_close = greyscale_close(self.white_pixel, s) + grey_close = closing(self.white_pixel, s) assert np.all(grey_close == self.white_pixel) def test_open_white_pixel(self): for s in self.selems: - assert np.all(greyscale_open(self.white_pixel, s) == 0) + assert np.all(opening(self.white_pixel, s) == 0) def test_close_black_pixel(self): for s in self.selems: - assert np.all(greyscale_close(self.black_pixel, s) == 255) + assert np.all(closing(self.black_pixel, s) == 255) def test_white_tophat_white_pixel(self): for s in self.selems: - tophat = greyscale_white_top_hat(self.white_pixel, s) + tophat = white_tophat(self.white_pixel, s) assert np.all(tophat == self.white_pixel) def test_black_tophat_black_pixel(self): for s in self.selems: - tophat = greyscale_black_top_hat(self.black_pixel, s) + tophat = black_tophat(self.black_pixel, s) assert np.all(tophat == (255 - self.black_pixel)) def test_white_tophat_black_pixel(self): for s in self.selems: - tophat = greyscale_white_top_hat(self.black_pixel, s) + tophat = white_tophat(self.black_pixel, s) assert np.all(tophat == 0) def test_black_tophat_white_pixel(self): for s in self.selems: - tophat = greyscale_black_top_hat(self.white_pixel, s) + tophat = black_tophat(self.white_pixel, s) assert np.all(tophat == 0) From 284753a7a4aced7bb272fc819a5c1f3a03b9cc7c Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 20 Dec 2011 20:04:32 -0800 Subject: [PATCH 3/8] Make test module runnable. --- skimage/morphology/tests/test_morphology.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/skimage/morphology/tests/test_morphology.py b/skimage/morphology/tests/test_morphology.py index 320c775d..c3745662 100644 --- a/skimage/morphology/tests/test_morphology.py +++ b/skimage/morphology/tests/test_morphology.py @@ -1,7 +1,7 @@ import os.path import numpy as np -from numpy.testing import assert_equal +from numpy import testing from skimage import data_dir from skimage.morphology.grey import * @@ -19,7 +19,7 @@ class TestMorphology(): expected_result = matlab_results[arrname] mask = strel_func(k) actual_result = morph_func(lena, mask) - assert_equal(expected_result, actual_result) + testing.assert_equal(expected_result, actual_result) k = k + 1 def test_erode_diamond(self): @@ -116,3 +116,7 @@ class TestEccentricStructuringElements(): tophat = black_tophat(self.white_pixel, s) assert np.all(tophat == 0) + +if __name__ == '__main__': + testing.run_module_suite() + From 8fb597b1411383119871480a3d3645b8a2d29491 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 20 Dec 2011 21:41:36 -0800 Subject: [PATCH 4/8] Fix dtype compatibility for functions in morphology.grey Cast input images using ``img_as_ubyte``. Note, tests don't currently pass for integer arrays (test skipped). --- skimage/morphology/grey.py | 40 ++++++++++++++------- skimage/morphology/tests/test_morphology.py | 35 ++++++++++++++++++ 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index 851c0c87..215678a8 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -9,6 +9,8 @@ import warnings import numpy as np +import skimage + eps = np.finfo(float).eps @@ -23,7 +25,7 @@ def erosion(image, selem, out=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - The image as a uint8 ndarray. + Image array. selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. @@ -38,7 +40,7 @@ def erosion(image, selem, out=None, shift_x=False, shift_y=False): Returns ------- - eroded : ndarray + eroded : uint8 array The result of the morphological erosion. Examples @@ -60,6 +62,8 @@ def erosion(image, selem, out=None, shift_x=False, shift_y=False): """ if image is out: raise NotImplementedError("In-place erosion not supported!") + image = skimage.img_as_ubyte(image) + try: import skimage.morphology.cmorph as cmorph out = cmorph.erode(image, selem, out=out, @@ -68,6 +72,7 @@ def erosion(image, selem, out=None, shift_x=False, shift_y=False): except ImportError: raise ImportError("cmorph extension not available.") + def dilation(image, selem, out=None, shift_x=False, shift_y=False): """Return greyscale morphological dilation of an image. @@ -79,7 +84,7 @@ def dilation(image, selem, out=None, shift_x=False, shift_y=False): ---------- image : ndarray - The image as a uint8 ndarray. + Image array. selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. @@ -94,7 +99,7 @@ def dilation(image, selem, out=None, shift_x=False, shift_y=False): Returns ------- - dilated : ndarray + dilated : uint8 array The result of the morphological dilation. Examples @@ -116,6 +121,8 @@ def dilation(image, selem, out=None, shift_x=False, shift_y=False): """ if image is out: raise NotImplementedError("In-place dilation not supported!") + image = skimage.img_as_ubyte(image) + try: from . import cmorph out = cmorph.dilate(image, selem, out=out, @@ -124,6 +131,7 @@ def dilation(image, selem, out=None, shift_x=False, shift_y=False): except ImportError: raise ImportError("cmorph extension not available.") + def opening(image, selem, out=None): """Return greyscale morphological opening of an image. @@ -135,7 +143,7 @@ def opening(image, selem, out=None): Parameters ---------- image : ndarray - The image as a uint8 ndarray. + Image array. selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. @@ -146,7 +154,7 @@ def opening(image, selem, out=None): Returns ------- - opening : ndarray + opening : uint8 array The result of the morphological opening. Examples @@ -174,6 +182,7 @@ def opening(image, selem, out=None): out = dilation(eroded, selem, out=out, shift_x=shift_x, shift_y=shift_y) return out + def closing(image, selem, out=None): """Return greyscale morphological closing of an image. @@ -185,7 +194,7 @@ def closing(image, selem, out=None): Parameters ---------- image : ndarray - The image as a uint8 ndarray. + Image array. selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. @@ -196,8 +205,8 @@ def closing(image, selem, out=None): Returns ------- - opening : ndarray - The result of the morphological opening. + closing : uint8 array + The result of the morphological closing. Examples -------- @@ -224,6 +233,7 @@ def closing(image, selem, out=None): out = erosion(dilated, selem, out=out, shift_x=shift_x, shift_y=shift_y) return out + def white_tophat(image, selem, out=None): """Return white top hat of an image. @@ -234,7 +244,7 @@ def white_tophat(image, selem, out=None): Parameters ---------- image : ndarray - The image as a uint8 ndarray. + Image array. selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. @@ -245,7 +255,7 @@ def white_tophat(image, selem, out=None): Returns ------- - opening : ndarray + opening : uint8 array The result of the morphological white top hat. Examples @@ -267,11 +277,13 @@ def white_tophat(image, selem, out=None): """ if image is out: raise NotImplementedError("Cannot perform white top hat in place.") + image = skimage.img_as_ubyte(image) out = opening(image, selem, out=out) out = image - out return out + def black_tophat(image, selem, out=None): """Return black top hat of an image. @@ -283,7 +295,7 @@ def black_tophat(image, selem, out=None): Parameters ---------- image : ndarray - The image as a uint8 ndarray. + Image array. selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. @@ -294,7 +306,7 @@ def black_tophat(image, selem, out=None): Returns ------- - opening : ndarray + opening : uint8 array The result of the black top filter. Examples @@ -316,6 +328,8 @@ def black_tophat(image, selem, out=None): """ if image is out: raise NotImplementedError("Cannot perform white top hat in place.") + image = skimage.img_as_ubyte(image) + out = closing(image, selem, out=out) out = out - image return out diff --git a/skimage/morphology/tests/test_morphology.py b/skimage/morphology/tests/test_morphology.py index c3745662..69fb60da 100644 --- a/skimage/morphology/tests/test_morphology.py +++ b/skimage/morphology/tests/test_morphology.py @@ -117,6 +117,41 @@ class TestEccentricStructuringElements(): assert np.all(tophat == 0) +class TestDTypes(): + + def setUp(self): + k = 5 + arrname = '%03i' % k + + self.disk = selem.disk(k) + + fname_opening = os.path.join(data_dir, "disk-open-matlab-output.npz") + self.expected_opening = np.load(fname_opening)[arrname] + + fname_closing = os.path.join(data_dir, "disk-close-matlab-output.npz") + self.expected_closing = np.load(fname_closing)[arrname] + + def _test_image(self, image): + result_opening = opening(image, self.disk) + testing.assert_equal(result_opening, self.expected_opening) + + result_closing = closing(image, self.disk) + testing.assert_equal(result_closing, self.expected_closing) + + def test_float(self): + image = skimage.img_as_float(lena) + self._test_image(image) + + @testing.decorators.skipif(True) + def test_int(self): + image = skimage.img_as_int(lena) + self._test_image(image) + + def test_uint(self): + image = skimage.img_as_uint(lena) + self._test_image(image) + + if __name__ == '__main__': testing.run_module_suite() From 0edefedc503d837829d4e1aab35187cd03d36a19 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Thu, 3 May 2012 17:35:11 -0400 Subject: [PATCH 5/8] Replace `import *` with `import grey`. --- skimage/morphology/tests/test_morphology.py | 47 +++++++++++---------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/skimage/morphology/tests/test_morphology.py b/skimage/morphology/tests/test_morphology.py index 69fb60da..1103b20d 100644 --- a/skimage/morphology/tests/test_morphology.py +++ b/skimage/morphology/tests/test_morphology.py @@ -3,8 +3,9 @@ import os.path import numpy as np from numpy import testing +import skimage from skimage import data_dir -from skimage.morphology.grey import * +from skimage.morphology import grey from skimage.morphology import selem @@ -24,43 +25,43 @@ class TestMorphology(): def test_erode_diamond(self): self.morph_worker(lena, "diamond-erode-matlab-output.npz", - erosion, selem.diamond) + grey.erosion, selem.diamond) def test_dilate_diamond(self): self.morph_worker(lena, "diamond-dilate-matlab-output.npz", - dilation, selem.diamond) + grey.dilation, selem.diamond) def test_open_diamond(self): self.morph_worker(lena, "diamond-open-matlab-output.npz", - opening, selem.diamond) + grey.opening, selem.diamond) def test_close_diamond(self): self.morph_worker(lena, "diamond-close-matlab-output.npz", - closing, selem.diamond) + grey.closing, selem.diamond) def test_tophat_diamond(self): self.morph_worker(lena, "diamond-tophat-matlab-output.npz", - white_tophat, selem.diamond) + grey.white_tophat, selem.diamond) def test_bothat_diamond(self): self.morph_worker(lena, "diamond-bothat-matlab-output.npz", - black_tophat, selem.diamond) + grey.black_tophat, selem.diamond) def test_erode_disk(self): self.morph_worker(lena, "disk-erode-matlab-output.npz", - erosion, selem.disk) + grey.erosion, selem.disk) def test_dilate_disk(self): self.morph_worker(lena, "disk-dilate-matlab-output.npz", - dilation, selem.disk) + grey.dilation, selem.disk) def test_open_disk(self): self.morph_worker(lena, "disk-open-matlab-output.npz", - opening, selem.disk) + grey.opening, selem.disk) def test_close_disk(self): self.morph_worker(lena, "disk-close-matlab-output.npz", - closing, selem.disk) + grey.closing, selem.disk) class TestEccentricStructuringElements(): @@ -74,46 +75,46 @@ class TestEccentricStructuringElements(): def test_dilate_erode_symmetry(self): for s in self.selems: - c = erosion(self.black_pixel, s) - d = dilation(self.white_pixel, s) + c = grey.erosion(self.black_pixel, s) + d = grey.dilation(self.white_pixel, s) assert np.all(c == (255 - d)) def test_open_black_pixel(self): for s in self.selems: - grey_open = opening(self.black_pixel, s) + grey_open = grey.opening(self.black_pixel, s) assert np.all(grey_open == self.black_pixel) def test_close_white_pixel(self): for s in self.selems: - grey_close = closing(self.white_pixel, s) + grey_close = grey.closing(self.white_pixel, s) assert np.all(grey_close == self.white_pixel) def test_open_white_pixel(self): for s in self.selems: - assert np.all(opening(self.white_pixel, s) == 0) + assert np.all(grey.opening(self.white_pixel, s) == 0) def test_close_black_pixel(self): for s in self.selems: - assert np.all(closing(self.black_pixel, s) == 255) + assert np.all(grey.closing(self.black_pixel, s) == 255) def test_white_tophat_white_pixel(self): for s in self.selems: - tophat = white_tophat(self.white_pixel, s) + tophat = grey.white_tophat(self.white_pixel, s) assert np.all(tophat == self.white_pixel) def test_black_tophat_black_pixel(self): for s in self.selems: - tophat = black_tophat(self.black_pixel, s) + tophat = grey.black_tophat(self.black_pixel, s) assert np.all(tophat == (255 - self.black_pixel)) def test_white_tophat_black_pixel(self): for s in self.selems: - tophat = white_tophat(self.black_pixel, s) + tophat = grey.white_tophat(self.black_pixel, s) assert np.all(tophat == 0) def test_black_tophat_white_pixel(self): for s in self.selems: - tophat = black_tophat(self.white_pixel, s) + tophat = grey.black_tophat(self.white_pixel, s) assert np.all(tophat == 0) @@ -132,10 +133,10 @@ class TestDTypes(): self.expected_closing = np.load(fname_closing)[arrname] def _test_image(self, image): - result_opening = opening(image, self.disk) + result_opening = grey.opening(image, self.disk) testing.assert_equal(result_opening, self.expected_opening) - result_closing = closing(image, self.disk) + result_closing = grey.closing(image, self.disk) testing.assert_equal(result_closing, self.expected_closing) def test_float(self): From 136a020088beba9a284ab4835b890b0f056b8821 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Thu, 3 May 2012 17:42:39 -0400 Subject: [PATCH 6/8] Remove unused variable. --- skimage/morphology/grey.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index 215678a8..a81cfc82 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -12,9 +12,6 @@ import numpy as np import skimage -eps = np.finfo(float).eps - - def erosion(image, selem, out=None, shift_x=False, shift_y=False): """Return greyscale morphological erosion of an image. From 9358d785c37322114b1bbc3ea949736558e6c2c1 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Thu, 3 May 2012 17:44:08 -0400 Subject: [PATCH 7/8] Add `__all__` to grey module. --- skimage/morphology/grey.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index a81cfc82..ee8542dd 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -12,6 +12,12 @@ import numpy as np import skimage +__all__ = ['erosion', 'dilation', 'opening', 'closing', 'white_tophat', + 'black_tophat', 'greyscale_erode', 'greyscale_dilate', + 'greyscale_open', 'greyscale_close', 'greyscale_white_top_hat', + 'greyscale_black_top_hat'] + + def erosion(image, selem, out=None, shift_x=False, shift_y=False): """Return greyscale morphological erosion of an image. From dc6c3d02228ee2351033e24480fdfe3f2888a2a2 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Thu, 3 May 2012 17:45:36 -0400 Subject: [PATCH 8/8] Rename test module to match module. --- skimage/morphology/tests/{test_morphology.py => test_grey.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename skimage/morphology/tests/{test_morphology.py => test_grey.py} (100%) diff --git a/skimage/morphology/tests/test_morphology.py b/skimage/morphology/tests/test_grey.py similarity index 100% rename from skimage/morphology/tests/test_morphology.py rename to skimage/morphology/tests/test_grey.py