Ask Your Question
0

why cv::cuda::createMedianFilter function is slower than cv::medianBlur?

asked 2016-07-04 05:14:25 -0600

amir_pro gravatar image

As you know, Ptr<Filter> cv::cuda::createMedianFilter (int srcType, int windowSize, int partition=128) function added to OpenCV3.1.0.

I'm trying to do a median filter on 8 bit large images (6000*6000) with custom window size(up to 21). I compare cv::medianBlur and cv::cuda::createMedianFilter and results was

windowSize    cv::medianBlur    cv::cuda::createMedianFilter
    3             0.071 sec         3.637 sec
    5             0.285 sec         3.679 sec
    11            2.641 sec         3.652 sec
    19            2.566 sec         3.719 sec

1) why cuda::createMedianFilter is slower than cv::medianBlur?

2) How can i write a kernel code to implement median filter that use opencv Mat with custom kernel size?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-07-04 12:15:53 -0600

Tetragramm gravatar image

What code are you using to test this?

Make sure you perform at least one iteration of each function before entering the timing loop, and do 1000 iterations of each inside the loop. Also, I suggest keeping the Mat.upload and GPUMat.download outside the timing loop, since you want to do as much on the GPU as possible, and so those should only be done once and re-used for everything you can.

edit flag offensive delete link more

Comments

Thanks for your answer. Why perform at least one iteration of each function before entering the timing loop? and why do 1000 iterations of each inside the loop?

amir_pro gravatar imageamir_pro ( 2016-07-04 13:58:17 -0600 )edit

The first iteration of each CUDA function often takes many times the normal duration. Doing one iteration first makes sure that CUDA is initialized and that all the memory is allocated, both for CUDA and for the normal function.

Doing many iterations and finding the average time for each means that you have much less influence from outside factors like the Operating System or other programs running.

Tetragramm gravatar imageTetragramm ( 2016-07-04 15:15:25 -0600 )edit

Thanks a lot. Did you implement cuda median filter that use OpenCV Mat?

amir_pro gravatar imageamir_pro ( 2016-07-04 22:14:25 -0600 )edit

Um, you don't. The openCV Mat is in the CPU memory, and to use the GPU, it needs to be moved to the GPU memory. That means uploading it to the GPU, which means using the GPUMat.

Tetragramm gravatar imageTetragramm ( 2016-07-05 07:27:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-04 05:14:25 -0600

Seen: 1,491 times

Last updated: Jul 04 '16