"num_pixels" gives keyError for regionprops_table in scikit-image as property

import skimage
import numpy as np
array = np.array(([1,1],[1,0]))
skimage.measure.regionprops_table(array, properties=("num_pixels", "area_filled"))

gives keyError for "num_pixels", even though it should be available as property. Is it a bug or am I doing something wrong? Thanks!


  • No it's not you, it's indeed a bug:

    It was fixed here but the fix is not yet released.

    Until it's released, if you are brave, you can modify your copy of the skimage/measure/ file to match the fix.

    Alternatively, as a workaround, you can use a custom property:

    def num_pixels(binary_image):
        return np.sum(binary_image.astype(int))
    table = skimage.measure.regionprops_table(