scipy.ndimage.morphology.binary_opening performance vs. cv2.morphologyEx

100 views
Skip to first unread message

Benny Lichtner

unread,
Oct 10, 2015, 2:25:55 AM10/10/15
to scikit-image
Hey, all. I've been using scipy.ndimage.morphology.binary_opening on images around 15000 x 5000 in size (scans of old seismograms!). I did a quick comparison with open cv's cv2.morphologyEx and noticed the cv2 opening was about 10x faster.

Is this expected? I don't know much about how scipy and opencv differ under the hood. If unexpected, I'll take a closer look at the two.

(I was kindly pointed to this google group by folks replying to my github issue: https://github.com/scipy/scipy/issues/5333.)

--Benny

Stefan van der Walt

unread,
Oct 10, 2015, 2:57:42 AM10/10/15
to scikit...@googlegroups.com
Hi Benny

On 2015-10-09 22:54:17, Benny Lichtner <kak0iy...@gmail.com> wrote:
> Hey, all. I've been using scipy.ndimage.morphology.binary_opening on images
> around 15000 x 5000 in size (scans of old seismograms!). I did a quick
> comparison with open cv's cv2.morphologyEx and noticed the cv2 opening was
> about 10x faster.
>
> Is this expected? I don't know much about how scipy and opencv differ under
> the hood. If unexpected, I'll take a closer look at the two.

That sounds about right; OpenCV has highly optimized code. In this
case, we are simply calling through to scipy's ndimage module. One
thing you can try is to parallelize the operation—if you had four cores,
then you'd probably get about a 3x speedup. See

skimage.util.apply_parallel

Another option would be to implement the specific operation you want in
numba (fortunately, binary opening is not hard to do).

> (I was kindly pointed to this google group by folks replying to my github
> issue: https://github.com/scipy/scipy/issues/5333.)

I see they already mentioned some of the things I did above—but feel
free to ask if you have any further questions!

Regards
Stéfan
Reply all
Reply to author
Forward
0 new messages