Cache parameters in regionprops_3D like scikit-image.measure.regionprops
See original GitHub issueCurrently, I think regionprops_3D calculates all structural parameters when it is called. I have a case where I only need bbox (which is offered by scikit-image.measure.regionprops). After digging, I solved this issue by reverting to scikit-image.measure.regionprops, and found that they cache all the properties and calculate them on demand rather than doing it all upfront, surely doing lots of unnecessary work. In my case, it wasn’t just performance, but kept me from doing what I wanted, since I get an error in the calculation of convex hull and my code crashes.
The first two examples of extracting the bboxes for each region in the code below (using scikit-image.measure.regionprops and then by extracting the bbox method from that method) take the same amount of time, whereas regionprops_3D fails with the error shown below.
More discussion: https://github.com/scikit-image/scikit-image/issues/4679
import porespy as ps
import skimage
import scipy
import time
im = ps.generators.cylinders([200,200,200], 5,1000, 0,90,None)#
#im = ps.generators.cylinders([500,500,500], 5,5000, 0,90,None)
#im = ps.generators.cylinders([700,700,700], 5,7000, 0,90,None)
#im = ps.generators.cylinders([1000,1000,1000], 5,10000, 0,90,None)
labeledim = skimage.measure.label(im)
props_start = time.time()
props = skimage.measure.regionprops(labeledim)
bboxes1 = [prop['bbox'] for prop in props]
print('regionprops time = '+str(time.time()-props_start))
extracted_start = time.time()
objs = scipy.ndimage.find_objects(labeledim)
bboxes2 = []
for i, sl in enumerate(objs):
thisbbox = tuple([sl[i].start for i in range(3)] + [sl[i].stop for i in range(3)])
bboxes2.append(thisbbox)
print('find_objects time = ' + str(time.time()-extracted_start))
psprop_start = time.time()
# fail
psprops = ps.metrics.regionprops_3D(labeledim)
bboxes3 = [prop['bbox'] for prop in psprops]
print('psprops time - '+str(time.time()-psprop_start))
print(bboxes1==bboxes2)
print(bboxes1==bboxes3)
regionprops time = 0.047591447830200195
find_objects time = 0.0462188720703125
Exception has occurred: QhullError
QH6154 Qhull precision error: Initial simplex is flat (facet 1 is coplanar with the interior point)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)

Top Related StackOverflow Question
At a meeting today, we realized that maybe it’s time to move to PoreSpy V2.0. This would allow us to make some breaking changes, including removing many of the redundant values from this function.
I haven’t looked at this function in ages, but I will try to take a look soon. The first thing I’ll do is figure out how to ‘defer’ the calculation of our props. Then we can address the duplications with the latest stuff in skimage.