mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-15 11:25:53 +08:00
Merge pull request #1787 from ahojnnes/rpropsfix
Various fixes and improvements
This commit is contained in:
@@ -215,3 +215,6 @@
|
||||
|
||||
- Jim Fienup, Alexander Iacchetta
|
||||
In-depth review of sub-pixel shift registration
|
||||
|
||||
- Damian Eads
|
||||
Structuring elements in morphology module.
|
||||
|
||||
@@ -56,7 +56,7 @@ def gabor_kernel(frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None,
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from skimage.filter import gabor_kernel
|
||||
>>> from skimage.filters import gabor_kernel
|
||||
>>> from skimage import io
|
||||
>>> from matplotlib import pyplot as plt # doctest: +SKIP
|
||||
|
||||
@@ -148,7 +148,7 @@ def gabor(image, frequency, theta=0, bandwidth=1, sigma_x=None,
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from skimage.filter import gabor
|
||||
>>> from skimage.filters import gabor
|
||||
>>> from skimage import data, io
|
||||
>>> from matplotlib import pyplot as plt # doctest: +SKIP
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from ._ccomp import label as _label
|
||||
|
||||
def label(input, neighbors=None, background=None, return_num=False,
|
||||
connectivity=None):
|
||||
connectivity=None):
|
||||
return _label(input, neighbors, background, return_num, connectivity)
|
||||
|
||||
label.__doc__ = _label.__doc__
|
||||
|
||||
@@ -157,7 +157,7 @@ class _RegionProperties(object):
|
||||
@property
|
||||
def euler_number(self):
|
||||
euler_array = self.filled_image != self.image
|
||||
_, num = label(euler_array, neighbors=8, return_num=True)
|
||||
_, num = label(euler_array, neighbors=8, return_num=True, background=-1)
|
||||
return -num + 1
|
||||
|
||||
@property
|
||||
@@ -473,7 +473,7 @@ def regionprops(label_image, intensity_image=None, cache=True):
|
||||
Examples
|
||||
--------
|
||||
>>> from skimage import data, util
|
||||
>>> from skimage.morphology import label
|
||||
>>> from skimage.measure import label
|
||||
>>> img = util.img_as_ubyte(data.coins()) > 110
|
||||
>>> label_img = label(img, connectivity=img.ndim)
|
||||
>>> props = regionprops(label_img)
|
||||
|
||||
@@ -128,14 +128,12 @@ def test_equiv_diameter():
|
||||
|
||||
|
||||
def test_euler_number():
|
||||
with expected_warnings(['`background`|CObject type']):
|
||||
en = regionprops(SAMPLE)[0].euler_number
|
||||
en = regionprops(SAMPLE)[0].euler_number
|
||||
assert en == 0
|
||||
|
||||
SAMPLE_mod = SAMPLE.copy()
|
||||
SAMPLE_mod[7, -3] = 0
|
||||
with expected_warnings(['`background`|CObject type']):
|
||||
en = regionprops(SAMPLE_mod)[0].euler_number
|
||||
en = regionprops(SAMPLE_mod)[0].euler_number
|
||||
assert en == -1
|
||||
|
||||
|
||||
@@ -374,9 +372,8 @@ def test_equals():
|
||||
r2 = regions[0]
|
||||
r3 = regions[1]
|
||||
|
||||
with expected_warnings(['`background`|CObject type']):
|
||||
assert_equal(r1 == r2, True, "Same regionprops are not equal")
|
||||
assert_equal(r1 != r3, True, "Different regionprops are equal")
|
||||
assert_equal(r1 == r2, True, "Same regionprops are not equal")
|
||||
assert_equal(r1 != r3, True, "Different regionprops are equal")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
__all__ = ['convex_hull_image', 'convex_hull_object']
|
||||
|
||||
import numpy as np
|
||||
from ..measure import grid_points_in_poly
|
||||
from ..measure._pnpoly import grid_points_in_poly
|
||||
from ._convex_hull import possible_hull
|
||||
from ..measure._label import label
|
||||
from ..util import unique_rows
|
||||
|
||||
try:
|
||||
from scipy.spatial import Delaunay
|
||||
except ImportError:
|
||||
Delaunay = None
|
||||
|
||||
|
||||
def convex_hull_image(image):
|
||||
"""Compute the convex hull image of a binary image.
|
||||
@@ -15,12 +20,12 @@ def convex_hull_image(image):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
image : ndarray
|
||||
image : (M, N) array
|
||||
Binary input image. This array is cast to bool before processing.
|
||||
|
||||
Returns
|
||||
-------
|
||||
hull : ndarray of bool
|
||||
hull : (M, N) array of bool
|
||||
Binary image with pixels in convex hull set to True.
|
||||
|
||||
References
|
||||
@@ -29,12 +34,13 @@ def convex_hull_image(image):
|
||||
|
||||
"""
|
||||
|
||||
image = image.astype(bool)
|
||||
if Delaunay is None:
|
||||
raise ImportError("Could not import scipy.spatial.Delaunay, "
|
||||
"only available in scipy >= 0.9.")
|
||||
|
||||
# Here we do an optimisation by choosing only pixels that are
|
||||
# the starting or ending pixel of a row or column. This vastly
|
||||
# limits the number of coordinates to examine for the virtual
|
||||
# hull.
|
||||
# limits the number of coordinates to examine for the virtual hull.
|
||||
coords = possible_hull(image.astype(np.uint8))
|
||||
N = len(coords)
|
||||
|
||||
@@ -48,12 +54,6 @@ def convex_hull_image(image):
|
||||
# scipy.spatial.Delaunay, so we remove them.
|
||||
coords = unique_rows(coords_corners)
|
||||
|
||||
try:
|
||||
from scipy.spatial import Delaunay
|
||||
except ImportError:
|
||||
raise ImportError('Could not import scipy.spatial, only available in '
|
||||
'scipy >= 0.9.')
|
||||
|
||||
# Subtract offset
|
||||
offset = coords.mean(axis=0)
|
||||
coords -= offset
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
"""
|
||||
:author: Damian Eads, 2009
|
||||
:license: modified BSD
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
from scipy import ndimage as ndi
|
||||
from .. import draw
|
||||
|
||||
|
||||
def square(width, dtype=np.uint8):
|
||||
"""Generates a flat, square-shaped structuring element.
|
||||
|
||||
@@ -37,7 +33,7 @@ def rectangle(width, height, dtype=np.uint8):
|
||||
"""Generates a flat, rectangular-shaped structuring element.
|
||||
|
||||
Every pixel in the rectangle generated for a given width and given height
|
||||
belongs to the neighboorhood.
|
||||
belongs to the neighborhood.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -65,7 +61,7 @@ def diamond(radius, dtype=np.uint8):
|
||||
"""Generates a flat, diamond-shaped structuring element.
|
||||
|
||||
A pixel is part of the neighborhood (i.e. labeled 1) if
|
||||
the city block/manhattan distance between it and the center of
|
||||
the city block/Manhattan distance between it and the center of
|
||||
the neighborhood is no greater than radius.
|
||||
|
||||
Parameters
|
||||
@@ -193,7 +189,7 @@ def octahedron(radius, dtype=np.uint8):
|
||||
|
||||
This is the 3D equivalent of a diamond.
|
||||
A pixel is part of the neighborhood (i.e. labeled 1) if
|
||||
the city block/manhattan distance between it and the center of
|
||||
the city block/Manhattan distance between it and the center of
|
||||
the neighborhood is no greater than radius.
|
||||
|
||||
Parameters
|
||||
|
||||
@@ -139,5 +139,6 @@ def test_object():
|
||||
|
||||
assert_raises(ValueError, convex_hull_object, image, 7)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
np.testing.run_module_suite()
|
||||
|
||||
Reference in New Issue
Block a user