-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Description
Description
Another quirk with moving to regionprops_table
from the regionprops
list generation.
When passing it in data that ends up having zero labels, regionprops_table
will raise an IndexError
as props_to_dict
in _regionprops.py
looks like it assumes non-zero regions found:
r = regions[0][prop]
is where the exception gets thrown, where we were more expecting empty lists/dicts as per the original regionprops behavior.
Way to reproduce
from skimage.data import binary_blobs
from skimage.measure import regionprops, regionprops_table, label
import numpy as np
blobs = binary_blobs()
rprops = regionprops(label(blobs))
print("regionprops iter result")
print(len(rprops))
blobs_table = regionprops_table(label(blobs), properties=['centroid', 'local_centroid'])
print("regionprops table result")
print(blobs_table)
# No regions, exceptions
noblobs = np.zeros((64, 64, 64))
no_rprops = regionprops(label(noblobs))
print(f'regionprops blank: {no_rprops}')
blank_table = regionprops_table(label(noblobs), properties=['centroid', 'local_centroid'])
Output
regionprops iter result
9
regionprops table result
{'centroid-0': array([119, 33, 17, 122, 278, 184, 347, 362, 449]), 'centroid-1': array([ 39, 240, 492, 441, 178, 155, 451, 325, 195]), 'local_centroid-0': array([119, 33, 17, 69, 154, 29, 127, 30, 75]), 'local_centroid-1': array([ 39, 153, 22, 108, 178, 29, 66, 28, 88])}
regionprops blank []
Traceback (most recent call last):
File "bblob.py", line 20, in <module>
notable = regionprops_table(label(noblobs), properties=['centroid', 'local_centroid'])
File "/opt/anaconda/envs/pipeline_env/lib/python3.7/site-packages/skimage/measure/_regionprops.py", line 625, in regionprops_table
return _props_to_dict(regions, properties=properties, separator=separator)
File "/opt/anaconda/envs/pipeline_env/lib/python3.7/site-packages/skimage/measure/_regionprops.py", line 504, in _props_to_dict
r = regions[0][prop]
IndexError: list index out of range
Version information
3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
[GCC 7.3.0]
Linux-4.15.0-66-generic-x86_64-with-debian-buster-sid
scikit-image version: 0.16.2
numpy version: 1.16.4
Metadata
Metadata
Assignees
Labels
No labels