mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-07 12:18:13 +08:00
Remove backwards-compatability of skimage.measure.regionprops
This commit is contained in:
@@ -9,8 +9,3 @@ Version 0.11
|
||||
`skimage.transform.PolynomialTransform._params`,
|
||||
`skimage.transform.PiecewiseAffineTransform.affines_*` attributes
|
||||
* Remove deprecated functions `skimage.filter.denoise_*`
|
||||
|
||||
Version 0.10
|
||||
------------
|
||||
* Remove backwards-compatability of `skimage.measure.regionprops`
|
||||
* Remove deprecated logger function in `skimage/__init__.py`
|
||||
|
||||
@@ -4,8 +4,6 @@ from math import sqrt, atan2, pi as PI
|
||||
import numpy as np
|
||||
from scipy import ndimage
|
||||
|
||||
from collections import MutableMapping
|
||||
|
||||
from skimage.morphology import convex_hull_image, label
|
||||
from skimage.measure import _moments
|
||||
|
||||
@@ -107,16 +105,15 @@ class _cached_property(object):
|
||||
return value
|
||||
|
||||
|
||||
class _RegionProperties(MutableMapping):
|
||||
class _RegionProperties(object):
|
||||
|
||||
def __init__(self, slice, label, label_image, intensity_image,
|
||||
cache_active, properties=None):
|
||||
cache_active):
|
||||
self.label = label
|
||||
self._slice = slice
|
||||
self._label_image = label_image
|
||||
self._intensity_image = intensity_image
|
||||
self._cache_active = cache_active
|
||||
self._properties = properties
|
||||
|
||||
@_cached_property
|
||||
def area(self):
|
||||
@@ -306,27 +303,15 @@ class _RegionProperties(MutableMapping):
|
||||
def weighted_moments_normalized(self):
|
||||
return _moments.moments_normalized(self.weighted_moments_central, 3)
|
||||
|
||||
|
||||
# Preserve dictionary interface
|
||||
def __delitem__(self, key):
|
||||
pass
|
||||
|
||||
def __len__(self):
|
||||
return len(self._properties or PROPS.values())
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
raise RuntimeError("Cannot assign region properties.")
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._properties or PROPS.values())
|
||||
return iter(PROPS.values())
|
||||
|
||||
def __getitem__(self, key):
|
||||
value = getattr(self, key, None)
|
||||
if value is not None:
|
||||
return value
|
||||
else: # backwards compatability
|
||||
warnings.warn('Usage of deprecated property name.',
|
||||
category=DeprecationWarning)
|
||||
print PROPS[key]
|
||||
return getattr(self, PROPS[key])
|
||||
|
||||
def __eq__(self, other):
|
||||
@@ -344,22 +329,15 @@ class _RegionProperties(MutableMapping):
|
||||
return True
|
||||
|
||||
|
||||
def regionprops(label_image, properties=None,
|
||||
intensity_image=None, cache=True):
|
||||
"""Measure properties of labelled image regions.
|
||||
def regionprops(label_image, intensity_image=None, cache=True):
|
||||
"""Measure properties of labeled image regions.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
label_image : (N, M) ndarray
|
||||
Labelled input image.
|
||||
properties : {'all', list}
|
||||
**Deprecated parameter**
|
||||
|
||||
This parameter is not needed any more since all properties are
|
||||
determined dynamically.
|
||||
|
||||
Labeled input image.
|
||||
intensity_image : (N, M) ndarray, optional
|
||||
Intensity image with same size as labelled image. Default is None.
|
||||
Intensity image with same size as labeled image. Default is None.
|
||||
cache : bool, optional
|
||||
Determine whether to cache calculated properties. The computation is
|
||||
much faster for cached properties, whereas the memory consumption
|
||||
@@ -500,9 +478,9 @@ def regionprops(label_image, properties=None,
|
||||
>>> img = util.img_as_ubyte(data.coins()) > 110
|
||||
>>> label_img = label(img)
|
||||
>>> props = regionprops(label_img)
|
||||
>>> props[0].centroid # centroid of first labelled object
|
||||
>>> props[0].centroid # centroid of first labeled object
|
||||
(22.729879860483141, 81.912285234465827)
|
||||
>>> props[0]['centroid'] # centroid of first labelled object
|
||||
>>> props[0]['centroid'] # centroid of first labeled object
|
||||
(22.729879860483141, 81.912285234465827)
|
||||
|
||||
"""
|
||||
@@ -512,12 +490,6 @@ def regionprops(label_image, properties=None,
|
||||
if label_image.ndim != 2:
|
||||
raise TypeError('Only 2-D images supported.')
|
||||
|
||||
if properties is not None:
|
||||
warnings.warn('The ``properties`` argument is deprecated and is '
|
||||
'not needed any more as properties are '
|
||||
'determined dynamically.',
|
||||
category=DeprecationWarning)
|
||||
|
||||
regions = []
|
||||
|
||||
objects = ndimage.find_objects(label_image)
|
||||
@@ -527,8 +499,8 @@ def regionprops(label_image, properties=None,
|
||||
|
||||
label = i + 1
|
||||
|
||||
props = _RegionProperties(sl, label, label_image,
|
||||
intensity_image, cache, properties=properties)
|
||||
props = _RegionProperties(sl, label, label_image, intensity_image,
|
||||
cache)
|
||||
regions.append(props)
|
||||
|
||||
return regions
|
||||
|
||||
@@ -23,9 +23,9 @@ INTENSITY_SAMPLE[1, 9:11] = 2
|
||||
|
||||
|
||||
def test_all_props():
|
||||
regions = regionprops(SAMPLE, 'all', INTENSITY_SAMPLE)[0]
|
||||
region = regionprops(SAMPLE, INTENSITY_SAMPLE)[0]
|
||||
for prop in PROPS:
|
||||
regions[prop]
|
||||
assert_equal(region[prop], getattr(region, PROPS[prop]))
|
||||
|
||||
|
||||
def test_dtype():
|
||||
@@ -336,20 +336,6 @@ def test_weighted_moments_normalized():
|
||||
assert_array_almost_equal(wnu, ref)
|
||||
|
||||
|
||||
def test_old_dict_interface():
|
||||
feats = regionprops(SAMPLE,
|
||||
['Area', 'Eccentricity', 'EulerNumber',
|
||||
'Extent', 'MinIntensity', 'MeanIntensity',
|
||||
'MaxIntensity', 'Solidity'],
|
||||
intensity_image=INTENSITY_SAMPLE)
|
||||
|
||||
np.array([list(props.values()) for props in feats], np.float)
|
||||
assert_equal(len(feats[0]), 8)
|
||||
def assign():
|
||||
feats[0]['Area'] = 0
|
||||
assert_raises(RuntimeError, assign)
|
||||
|
||||
|
||||
def test_label_sequence():
|
||||
a = np.empty((2, 2), dtype=np.int)
|
||||
a[:, :] = 2
|
||||
|
||||
Reference in New Issue
Block a user