regionprops Very slow on centroid identification
Johannes Schoenberger
jsch at demuc.de
Wed Nov 26 10:52:29 EST 2014
Hi Jeff,
I mentioned this before, but since you do not care about individual regions, there is no reason to burden yourself with the overhead of the regionprops function.
Try this modified function:
```
def barycenter_skimage2(image,minx,miny,maxx,maxy,thresh,border,White_Mark):
"""
skimage computation of the barycenter (moment 1 of image) on ZOI using regionprops
"""
bw=image[minx:maxx+1,miny:maxy+1]>thresh
if(White_Mark==False):
bw=1-bw
Onex,Oney=np.where(bw==1)
minx_=Onex.min()
maxx_=Onex.max()
miny_=Oney.min()
maxy_=Oney.max()
M = measure.moments(bw.astype(np.double), order=1)
Px=M[0, 1]/M[0, 0]
Py=M[1, 0]/M[0, 0]
Px+=minx
Py+=miny
# Determination of the new bounding box using global coordinates and the margin
minx=minx-border+minx_
miny=miny-border+miny_
maxx=minx+border+maxx_
maxy=miny+border+maxy_
return Px,Py,minx,miny,maxx,maxy
```
We could add a templated version of the moments functions for uint8 to make this a fairer comparison. The regionprops function would also gain from this, since the `double` version is only used for the weighted moments.
Best, Johannes
> On Nov 26, 2014, at 9:28 AM, jeff witz <witzjean at gmail.com> wrote:
>
> Hi,
>
> Thank you all for your answers. finally I use OpenCV to perform the real-time computation and still use skimage for the initialisation on my real code.
>
> I've joined a file that allows one to compare the computation we need to make.
>
> There is a basic numpy method, the OpenCV one and the Skimage regionprops one. I don't find relevant to include a naive python implementation.
>
> Please note that the values computed for visualization are for illustration only and doesn't represent a real experiment.
>
> I Hope it can help to benchmark the future improvement of regionprops.
>
> Best regards
>
> --
> You received this message because you are subscribed to the Google Groups "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> <UnitTestExtenso.py>
More information about the scikit-image
mailing list