Ask Your Question
3

Some bizzare behavior of the median filter

asked 2016-05-12 10:06:32 -0500

NewDeveloper gravatar image

Dear great OpenCV community,

I apply the median image filter on an 8 bit unsigned char image with the resolution of 512x512. I have down sampled my image cause not all kernel sizes are supported by 16bit images. I'd checked the execution times of the mentioned filter for several kernel sizes. As a result I can observe that the execution time growth with the kernel size. Till there every thing is like I had expected. But if the kernel size is bigger than 15x15 the computational time decreases by a factor of two. Now I wonder that a kernel size of 99x99 takes about 9 ms and a kernel size of 15x15 about 16 ms. Can somebody give me an answer why this happens? My Thought is that the median filter is "just" a sorting algorithm and if the size becomes bigger the sorting should take more time.

I hope some one knows why this strange behaviour appears and can explain it a bit.

Best Regards NewDev

edit retag flag offensive close merge delete

Comments

Using this program

int main(int argc, char **argv)
{


Mat m1 = imread("f:/lib/opencv/samples/data/lena.jpg",IMREAD_GRAYSCALE);
Mat dst;
cout << " m1 ="<<m1.size() << "\n";
for (int i = 3; i < 65; i += 2)
{
    medianBlur(m1,dst,i);
    high_resolution_clock::time_point tp1 = std::chrono::high_resolution_clock::now();
    for(int j=0;j<20;j++)
        medianBlur(m1,dst,i);
    high_resolution_clock::time_point tp2 = std::chrono::high_resolution_clock::now();
    duration<double> time_span = duration_cast<duration<double>>(tp2 - tp1);
    cout << "Size " << i << " -> time medianBlur(x20) =" << time_span.count()<<endl;
}
}

I have : (next comment)

LBerger gravatar imageLBerger ( 2016-05-12 11:03:16 -0500 )edit

with previous program I have

Size 3 =0.002
Size 5 =0.014
Size 7 =0.574
Size 9 =0.621
Size 11 =0.651
Size 13 =0.749
Size 15 =0.771
Size 17 =1.37
Size 19 =1.34
Size 21 =1.36
Size 23 =1.38
Size 25 =1.39
Size 27 =1.4
Size 29 =1.41
Size 31 =1.42
Size 33 =1.44
Size 35 =1.46
Size 37 =1.46
Size 39 =1.47
Size 41 =1.48
Size 43 =1.54
Size 45 =1.51
Size 47 =1.51
Size 49 =1.52
Size 51 =1.54
Size 53 =1.55
Size 55 =1.56
Size 57 =1.56
Size 59 =1.57
Size 61 =1.62
Size 63 =1.59
LBerger gravatar imageLBerger ( 2016-05-12 11:07:37 -0500 )edit

oh sry I forget to say that I run it in release mode,.... in debug mode everything works like expected but in release it has some strange behavior

NewDeveloper gravatar imageNewDeveloper ( 2016-05-12 11:46:47 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-05-12 12:25:39 -0500

LBerger gravatar image

updated 2016-05-12 12:27:10 -0500

Yes nothing strange the answer is in figure 5 (reference given in source code)

edit flag offensive delete link more

Comments

Thank you LBerger for taking time and give me helpfully answers! BR

NewDeveloper gravatar imageNewDeveloper ( 2016-05-12 13:39:46 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-05-12 10:06:32 -0500

Seen: 140 times

Last updated: May 12 '16