mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-12 06:19:35 +08:00
Merge branch 'master' of https://github.com/scikit-image/scikit-image
This commit is contained in:
@@ -503,6 +503,9 @@ def regionprops(label_image, properties=None,
|
||||
|
||||
objects = ndimage.find_objects(label_image)
|
||||
for i, sl in enumerate(objects):
|
||||
if sl is None:
|
||||
continue
|
||||
|
||||
label = i + 1
|
||||
|
||||
props = _RegionProperties(sl, label, label_image,
|
||||
|
||||
@@ -347,6 +347,20 @@ def test_old_dict_interface():
|
||||
assert_equal(len(feats[0]), 8)
|
||||
|
||||
|
||||
def test_label_sequence():
|
||||
a = np.empty((2, 2), dtype=np.int)
|
||||
a[:, :] = 2
|
||||
ps = regionprops(a)
|
||||
assert len(ps) == 1
|
||||
assert ps[0].label == 2
|
||||
|
||||
|
||||
def test_pure_background():
|
||||
a = np.zeros((2, 2), dtype=np.int)
|
||||
ps = regionprops(a)
|
||||
assert len(ps) == 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from numpy.testing import run_module_suite
|
||||
run_module_suite()
|
||||
|
||||
@@ -341,7 +341,7 @@ class AffineTransform(ProjectiveTransform):
|
||||
return self._matrix[0:2, 2]
|
||||
|
||||
|
||||
class PiecewiseAffineTransform(ProjectiveTransform):
|
||||
class PiecewiseAffineTransform(GeometricTransform):
|
||||
|
||||
"""2D piecewise affine transformation.
|
||||
|
||||
@@ -1031,21 +1031,24 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
|
||||
out = None
|
||||
|
||||
# use fast Cython version for specific interpolation orders
|
||||
# use fast Cython version for specific interpolation orders and input
|
||||
if order in range(4) and not map_args:
|
||||
|
||||
matrix = None
|
||||
|
||||
# inverse_map is a transformation matrix as numpy array
|
||||
if isinstance(inverse_map, np.ndarray) and inverse_map.shape == (3, 3):
|
||||
matrix = inverse_map
|
||||
|
||||
elif inverse_map in HOMOGRAPHY_TRANSFORMS:
|
||||
# inverse_map is a homography
|
||||
elif isinstance(inverse_map, HOMOGRAPHY_TRANSFORMS):
|
||||
matrix = inverse_map._matrix
|
||||
|
||||
# inverse_map is the inverse of a homography
|
||||
elif (hasattr(inverse_map, '__name__')
|
||||
and inverse_map.__name__ == 'inverse'
|
||||
and get_bound_method_class(inverse_map)
|
||||
in HOMOGRAPHY_TRANSFORMS):
|
||||
|
||||
and isinstance(get_bound_method_class(inverse_map),
|
||||
HOMOGRAPHY_TRANSFORMS)):
|
||||
matrix = np.linalg.inv(six.get_method_self(inverse_map)._matrix)
|
||||
|
||||
if matrix is not None:
|
||||
@@ -1067,6 +1070,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
|
||||
rows, cols = output_shape[:2]
|
||||
|
||||
# inverse_map is a transformation matrix as numpy array
|
||||
if isinstance(inverse_map, np.ndarray) and inverse_map.shape == (3, 3):
|
||||
inverse_map = ProjectiveTransform(matrix=inverse_map)
|
||||
|
||||
@@ -1075,19 +1079,19 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
|
||||
coords = warp_coords(coord_map, (rows, cols, bands))
|
||||
|
||||
# Prefilter not necessary for order 0, 1 interpolation
|
||||
# Pre-filtering not necessary for order 0, 1 interpolation
|
||||
prefilter = order > 1
|
||||
out = ndimage.map_coordinates(image, coords, prefilter=prefilter,
|
||||
mode=mode, order=order, cval=cval)
|
||||
|
||||
# The spline filters sometimes return results outside [0, 1],
|
||||
# so clip to ensure valid data
|
||||
clipped = np.clip(out, 0, 1)
|
||||
# The spline filters sometimes return results outside [0, 1],
|
||||
# so clip to ensure valid data
|
||||
clipped = np.clip(out, 0, 1)
|
||||
|
||||
if mode == 'constant' and not (0 <= cval <= 1):
|
||||
clipped[out == cval] = cval
|
||||
if mode == 'constant' and not (0 <= cval <= 1):
|
||||
clipped[out == cval] = cval
|
||||
|
||||
out = clipped
|
||||
out = clipped
|
||||
|
||||
if out.ndim == 3 and orig_ndim == 2:
|
||||
# remove singleton dimension introduced by atleast_3d
|
||||
|
||||
@@ -89,11 +89,11 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None,
|
||||
|
||||
cdef Py_ssize_t out_r, out_c
|
||||
if output_shape is None:
|
||||
out_r = img.shape[0]
|
||||
out_c = img.shape[1]
|
||||
out_r = int(img.shape[0])
|
||||
out_c = int(img.shape[1])
|
||||
else:
|
||||
out_r = output_shape[0]
|
||||
out_c = output_shape[1]
|
||||
out_r = int(output_shape[0])
|
||||
out_c = int(output_shape[1])
|
||||
|
||||
cdef double[:, ::1] out = np.zeros((out_r, out_c), dtype=np.double)
|
||||
|
||||
|
||||
@@ -20,12 +20,28 @@ __all__ = ['ImageViewer', 'CollectionViewer']
|
||||
def mpl_image_to_rgba(mpl_image):
|
||||
"""Return RGB image from the given matplotlib image object.
|
||||
|
||||
Each image in a matplotlib figure has it's own colormap and normalization
|
||||
Each image in a matplotlib figure has its own colormap and normalization
|
||||
function. Return RGBA (RGB + alpha channel) image with float dtype.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
mpl_image : matplotlib.image.AxesImage object
|
||||
The image being converted.
|
||||
|
||||
Returns
|
||||
-------
|
||||
img : array of float, shape (M, N, 4)
|
||||
An image of float values in [0, 1].
|
||||
"""
|
||||
input_range = (mpl_image.norm.vmin, mpl_image.norm.vmax)
|
||||
image = rescale_intensity(mpl_image.get_array(), in_range=input_range)
|
||||
image = mpl_image.cmap(img_as_float(image)) # cmap complains on bool arrays
|
||||
image = mpl_image.get_array()
|
||||
if image.ndim == 2:
|
||||
input_range = (mpl_image.norm.vmin, mpl_image.norm.vmax)
|
||||
image = rescale_intensity(image, in_range=input_range)
|
||||
# cmap complains on bool arrays
|
||||
image = mpl_image.cmap(img_as_float(image))
|
||||
elif image.ndim == 3 and image.shape[2] == 3:
|
||||
# add alpha channel if it's missing
|
||||
image = np.dstack((image, np.ones_like(image)))
|
||||
return img_as_float(image)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user