Skip to content
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 missing num_pixels as a property in stable #7038

Closed
rsmaior opened this issue Jun 26, 2023 · 1 comment · Fixed by #7039
Closed

measure.regionprops_table missing num_pixels as a property in stable #7038

rsmaior opened this issue Jun 26, 2023 · 1 comment · Fixed by #7039
Labels

Comments

@rsmaior
Copy link

rsmaior commented Jun 26, 2023

Description:

Reading the stable documentation here: https://scikit-image.org/docs/stable/api/skimage.measure.html#skimage.measure.regionprops

We have:

num_pixels: int
Number of foreground pixels.

But whe trying to use that property I get errors.

Way to reproduce:

Example code:

import math
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from skimage.draw import ellipse
from skimage.measure import label, regionprops, regionprops_table
from skimage.transform import rotate


image = np.zeros((600, 600))

rr, cc = ellipse(300, 350, 100, 220)
image[rr, cc] = 1

image = rotate(image, angle=15, order=0)

rr, cc = ellipse(100, 100, 60, 50)
image[rr, cc] = 1

label_img = label(image)
regions = regionprops(label_img)

props = regionprops_table(label_img, properties=('area', 'num_pixels', 'slice'))

And the generated error:

  Cell In[47], line 14
    props = regionprops_table(label_img, properties=('area', 'num_pixels', 'slice'))

  File ~\anaconda3\envs\ai\lib\site-packages\skimage\measure\_regionprops.py:1045 in regionprops_table
    return _props_to_dict(

  File ~\anaconda3\envs\ai\lib\site-packages\skimage\measure\_regionprops.py:841 in _props_to_dict
    func = r._extra_properties[prop]

KeyError: 'num_pixels'

Version information:

3.9.16 (main, Mar  8 2023, 10:39:24) [MSC v.1916 64 bit (AMD64)]
Windows-10-10.0.19045-SP0
scikit-image version: 0.20.0
numpy version: 1.24.3

Related issues

There's an older related issue here, but it was not valid since in that time num_pixels were only in the unstable scikit #6337

@jni
Copy link
Member

jni commented Jun 27, 2023

Oops! Thanks for the report @rsmaior! When fixing and writing a test for the fix, I actually caught another missing property. So, thank you for helping us find these! Fix in #7039.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants