Separated Filter is slower

Separated Filter is slower

by Naravich Chutisilp -
Number of replies: 2

Hi,

I have encountered the problem with separated filter being slower than the 2D filter.

I implemented the applyImageFilter as such.


The separated filter was then implement as the following




However, the performance of the separated filter is shown in the following


while the 2D filter perform the following 



Thank you in advanced!

In reply to Naravich Chutisilp

Re: Separated Filter is slower

by Naravich Chutisilp -
Okay, I have found out that for this to work, I had to implement the applyImageFilter with 4 for loop which returned exactly 0.0 error with scipy's implementation (my implementation got 6e-9 error which I though was low enough)
In reply to Naravich Chutisilp

Re: Separated Filter is slower

by Hussein Osman -
Hi Naravich,

As you pointed out, it is all about how you implement the convolution function. If you performed element-wise multiplication for filter convolution using loops and standard multiplication, then it would definitely take more time than if you were to use np.multiply(). Only then, you would have observed the difference in performance between the separated filters and the 2D filter.
You can write a simple test code to check the time difference between both implementations. For example, the standard element-wise multiplication of two 1000x1000 matrices would take around 0.432s, whereas the numpy function would take 0.003s. (numbers may differ for different machines, but the difference in magnitude would always be comparable).