New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
measure.regionprops_table
with properties=['centroid_weighted']
fails on images with >1 color channel.
#6860
Comments
Thanks for the report, @aslyon! The issue is here: scikit-image/skimage/measure/_regionprops.py Lines 857 to 860 in c7fb481
It turns out that the output of import numpy as np
import skimage
# Create 3D label image with a sphere
label_img = np.zeros((9, 9, 9), dtype='uint8')
label_img[:, :, :] = skimage.morphology.ball(radius=4)
n_pixels = label_img.sum()
# Create random number generator
rng = np.random.default_rng(seed=123)
# Create intensity image of sphere filled with random values
intensity_img = np.zeros((9, 9, 9, 3))
intensity_img[:, :, :, 0][label_img == 1] = rng.uniform(low=10, high=20, size=n_pixels)
intensity_img[:, :, :, 1][label_img == 1] = rng.uniform(low=10, high=20, size=n_pixels)
intensity_img[:, :, :, 2][label_img == 1] = rng.uniform(low=10, high=20, size=n_pixels)
# Measure props for no channel axis:
props0 = skimage.measure.regionprops(label_img, intensity_img[..., 0])[0]
print(f'no channel:\n {props0.centroid_weighted}')
# Measure props for single channel
props1 = skimage.measure.regionprops(label_img, intensity_img[..., 0:1])[0]
print(f'one channel:\n {props1.centroid_weighted}')
# Measure props for multiple channels
propsm = skimage.measure.regionprops(label_img, intensity_img)[0]
print(f'multichannel:\n {propsm.centroid_weighted}') which gives:
So, it looks like we need a better way of identifying the type and shape of the output of each property when turning it into a table. My first instinct is to convert any non-scalar, non-object property to an array. I might give that a go. |
Working correctly now, thanks so much for the rapid response @jni ! |
Description:
Calling
skimage.measure.regionprops_table
withproperties=['centroid_weighted']
on an image with >1 color channel raisesValueError: setting an array element with a sequence.
I expected to get a dictionary with keyscentroid_weighted-n-c
wheren
are the indices of the spatial dimensions andc
are the indices of the color channels.Way to reproduce:
The
ValueError
with traceback is below. The error is the same whether 2 or 3 color intensity image is used.Version information:
The text was updated successfully, but these errors were encountered: