From e74b9713351cb5eea80a2e8ed4e250583bd5a7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sat, 6 Jul 2013 14:30:17 +0200 Subject: [PATCH 1/3] erode & dilate -> private functions --- skimage/morphology/cmorph.pyx | 4 ++-- skimage/morphology/grey.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/skimage/morphology/cmorph.pyx b/skimage/morphology/cmorph.pyx index a09a39a3..05dba333 100644 --- a/skimage/morphology/cmorph.pyx +++ b/skimage/morphology/cmorph.pyx @@ -8,7 +8,7 @@ cimport numpy as np from libc.stdlib cimport malloc, free -def dilate(np.ndarray[np.uint8_t, ndim=2] image, +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): @@ -63,7 +63,7 @@ def dilate(np.ndarray[np.uint8_t, ndim=2] image, return out -def erode(np.ndarray[np.uint8_t, ndim=2] image, +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): diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index 2cca69b6..233bca4a 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -58,7 +58,7 @@ def erosion(image, selem, out=None, shift_x=False, shift_y=False): raise NotImplementedError("In-place erosion not supported!") image = img_as_ubyte(image) selem = img_as_ubyte(selem) - return cmorph.erode(image, selem, out=out, + return cmorph._erode(image, selem, out=out, shift_x=shift_x, shift_y=shift_y) @@ -111,7 +111,7 @@ def dilation(image, selem, out=None, shift_x=False, shift_y=False): raise NotImplementedError("In-place dilation not supported!") image = img_as_ubyte(image) selem = img_as_ubyte(selem) - return cmorph.dilate(image, selem, out=out, + return cmorph._dilate(image, selem, out=out, shift_x=shift_x, shift_y=shift_y) From f316abbfbedcfe5292e0bf0d53ad5265aec03428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sat, 6 Jul 2013 14:34:55 +0200 Subject: [PATCH 2/3] DOC: add doctrings --- skimage/morphology/cmorph.pyx | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/skimage/morphology/cmorph.pyx b/skimage/morphology/cmorph.pyx index 05dba333..2e0fa88a 100644 --- a/skimage/morphology/cmorph.pyx +++ b/skimage/morphology/cmorph.pyx @@ -12,7 +12,30 @@ 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): + """Return greyscale morphological erosion of an image. + Morphological erosion sets a pixel at (i,j) to the minimum over all pixels + in the neighborhood centered at (i,j). Erosion shrinks bright regions and + enlarges dark regions. + + Parameters + ---------- + image : ndarray + Image array. + selem : ndarray + The neighborhood expressed as a 2-D array of 1's and 0's. + out : ndarray + The array to store the result of the morphology. If None is + passed, a new array will be allocated. + shift_x, shift_y : bool + shift structuring element about center point. This only affects + eccentric structuring elements (i.e. selem with even numbered sides). + + Returns + ------- + eroded : uint8 array + The result of the morphological erosion. + """ cdef Py_ssize_t rows = image.shape[0] cdef Py_ssize_t cols = image.shape[1] cdef Py_ssize_t srows = selem.shape[0] @@ -67,6 +90,31 @@ 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): + """Return greyscale morphological dilation of an image. + + Morphological dilation sets a pixel at (i,j) to the maximum over all pixels + in the neighborhood centered at (i,j). Dilation enlarges bright regions + and shrinks dark regions. + + Parameters + ---------- + + image : ndarray + Image array. + selem : ndarray + The neighborhood expressed as a 2-D array of 1's and 0's. + out : ndarray + The array to store the result of the morphology. If None, is + passed, a new array will be allocated. + shift_x, shift_y : bool + shift structuring element about center point. This only affects + eccentric structuring elements (i.e. selem with even numbered sides). + + Returns + ------- + dilated : uint8 array + The result of the morphological dilation. + """ cdef Py_ssize_t rows = image.shape[0] cdef Py_ssize_t cols = image.shape[1] From de9d2662b1e4e8a74bfead39b84fa3d6bba2ce2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sat, 6 Jul 2013 14:45:54 +0200 Subject: [PATCH 3/3] MIN: fix pep8 --- skimage/morphology/cmorph.pyx | 12 ++++++------ skimage/morphology/grey.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/skimage/morphology/cmorph.pyx b/skimage/morphology/cmorph.pyx index 2e0fa88a..070c881b 100644 --- a/skimage/morphology/cmorph.pyx +++ b/skimage/morphology/cmorph.pyx @@ -9,9 +9,9 @@ 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): + 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): """Return greyscale morphological erosion of an image. Morphological erosion sets a pixel at (i,j) to the minimum over all pixels @@ -87,9 +87,9 @@ def _dilate(np.ndarray[np.uint8_t, ndim=2] image, 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): + 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): """Return greyscale morphological dilation of an image. Morphological dilation sets a pixel at (i,j) to the maximum over all pixels diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index 233bca4a..ef7158b2 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -59,7 +59,7 @@ def erosion(image, selem, out=None, shift_x=False, shift_y=False): image = img_as_ubyte(image) selem = img_as_ubyte(selem) return cmorph._erode(image, selem, out=out, - shift_x=shift_x, shift_y=shift_y) + shift_x=shift_x, shift_y=shift_y) def dilation(image, selem, out=None, shift_x=False, shift_y=False): @@ -112,7 +112,7 @@ def dilation(image, selem, out=None, shift_x=False, shift_y=False): image = img_as_ubyte(image) selem = img_as_ubyte(selem) return cmorph._dilate(image, selem, out=out, - shift_x=shift_x, shift_y=shift_y) + shift_x=shift_x, shift_y=shift_y) def opening(image, selem, out=None):