question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache parameters in regionprops_3D like scikit-image.measure.regionprops

See original GitHub issue

Currently, 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:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jgostickcommented, May 22, 2020

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.

1reaction
jgostickcommented, May 13, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module: measure — skimage v0.19.2 docs
skimage.measure.regionprops (label_image[, …]) ... Compute image properties and return them as a pandas-compatible table. ... Parameters. coords(N, 2) array.
Read more >
Allow for calculation of single property in regionprops #4679
They implement regionprops_3d, which first calls skimage.measure.regionprops, then extends it. It seems like they don't do caching.
Read more >
Calculating just a specific property in regionprops python
Same calculation using regionprops: %%time rps = skimage.measure.regionprops(labels, cache=False) area2 = [r.area for r in rps].
Read more >
regionprops Very slow on centroid identification
http://scikit-image.org/docs/dev/auto_examples/plot_label.html. Then I compute the center of mass on each ZOI. As I have a fast camera the ZOI between two ...
Read more >
Module: measure — skimage v0.10dev docs
skimage.measure.regionprops(label_image[, . ... This function must implement an axis parameter such as numpy.sum or numpy.min. cval : float.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found