Ask Your Question
0

speed of top hat filter

asked 2016-05-29 01:06:01 -0600

farideh64 gravatar image

Hi, I have a problem with speed of a top hat filter. In an IEEE transaction paper, the running time of top hat applied to an image with resolution 320× 256 is estimated 0.0062 second with MATLAB software on a PC with 8-GB memory and 4-GHz Intel i7 processor. table_time I run the following code with openCV on a laptop with 6-GB memory and 2.6-GHz Intel i5 processor for this image with the same resolution: image description

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
    double t0 = (double)getTickCount();
    Mat src,dst;
    src=imread("E:/tree.jpg",0);
    Mat element = getStructuringElement(MORPH_ELLIPSE,Size(3,3));
    morphologyEx(src,dst,MORPH_TOPHAT,element,Point(-1,-1));
    double elapsed=((double)getTickCount()-t0)/getTickFrequency();
    cout<<elapsed<<"second"<<"\n";
    imshow("src",src);
    imshow("dst",dst);
    waitKey(0);
    return -1;
}

It takes .05375 second. In spite of the the fact that C++ and openCV are fast, but why the running time of top hat is 6 ms in matlab and 54 ms in opencv. how I could accelerate it?

image description

edit retag flag offensive close merge delete

Comments

my answer is at SO

sturkmen gravatar imagesturkmen ( 2016-05-29 04:50:00 -0600 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2016-05-30 03:20:44 -0600

kbarni gravatar image

Don't measure elapsed time with getTickCount! It gives you the processor ticks (operations), and your processor can make several operations in parallel.

Use clock_gettime() function to measure precisely elapsed time.

And don't measure image loading time in the filtering, as disk operations can be slow.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-29 01:06:01 -0600

Seen: 585 times

Last updated: May 30 '16