Hi Jeff,
Firstly, what's with all the trailing underscores? Makes my brain hurt. =)
Second, this is *somewhat* of a known issue. See:
(Including the notebook link from that issue.)
As you can see,
PR 1096 made some improvements, but I suspect not enough to solve your problem. Are you on master or on 0.10?
Additionally, regionprops works through a "cached-property" pattern, which means that each value is computed once, and then stored for later retrieval. So your second region[0] call is probably hitting the cached value, hence the massive speedup!
As to the specific problem of why your calculation is so much faster, my guess right now is that it's because of Python function call overhead: while you are computing everything directly, have a look at the regionprops
code: first, you have to go through the cached-property pattern (1 call), check whether the cache is active (2 calls), check whether it's been computed before (3 calls), decide to compute it (4 calls), compute the bbox (another travel through cached-property), then compute the "local" centroid (relative to current bbox), within that compute the moments (another cached-property), and *finally* compute the actual centroid.
We're not doing any computations differently, but that is a *heck* of a lot of overhead for such a simple computation. I'd never followed this full path before, so thanks for pointing it out! A PR to improve this situation would be most welcome! (Bonus points for improving 3D support in the process.)
Probably not quite the quick fix you were hoping for, but I hope this helps nonetheless!
Juan.