Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Implement imfilter(matlab) with OpenCV

Hello,

I am trying to port matlab code to c++ with opencv. I could import most source code but I had serious problems with the imfilter function. I was trying to use the filter2d function for c++, but It doesn't get same results between among themselves. What is the difference? How I could get the same result? The source code is very simple.....

    //src_gray has one channel
    //C++ code
filter2D(src_gray, dst,-1, kernel);

    //Matlab code 
    dst = imfilter(src_gray,kernel)

Implement imfilter(matlab) with OpenCV

Hello,

I am trying to port matlab code to c++ with opencv. I could import most source code but I had serious problems with the imfilter function. I was trying to use the filter2d function for c++, but It doesn't get same results between among themselves. What is the difference? How I could get the same result? The source code is very simple.....

    //src_gray has one channel
    //C++ code
filter2D(src_gray, dst,-1, kernel);

    //Matlab code 
    dst = imfilter(src_gray,kernel)

Inputs: src_gray=

11    11    11    11    11
11    11    11    11    11

kernel =

 2     2
 2     2

output:

Matlab:

ans =

88    88    88    88    44
44    44    44    44    22

C++: [88 88 88 88 88; 88 88 88 88 88]

My c++ code:

/// Initialize arguments for the filter Point anchor( -1, -1 ); double delta = 0; int ddepth = -1; Mat dst;

float data[2][5] = {{11,11,11,11,11},{11,11,11,11,11}}; float kernel[2][2] = {{2,2},{2,2}};

Mat src = Mat(2, 5, CV_32FC1, &data); Mat ker = Mat(2, 2, CV_32FC1, &kernel);

filter2D(src, dst, ddepth , ker,anchor); cout << dst << endl;

char c; scanf("%c",&c);

Implement imfilter(matlab) with OpenCV

Hello,

I am trying to port matlab code to c++ with opencv. I could import most source code but I had serious problems with the imfilter function. I was trying to use the filter2d function for c++, but It doesn't get same results between among themselves. What is the difference? How I could get the same result? The source code is very simple.....

    //src_gray has one channel
    //C++ code
filter2D(src_gray, dst,-1, kernel);

    //Matlab code 
    dst = imfilter(src_gray,kernel)

Inputs: src_gray=

11    11    11    11    11
11    11    11    11    11

kernel =

 2     2
 2     2

output:

Matlab:

ans =

88    88    88    88    44
44    44    44    44    22

C++: [88 88 88 88 88; 88 88 88 88 88]

My c++ code:

/// Initialize arguments for the filter
 Point anchor( -1, -1 );
 double delta = 0;
 int ddepth = -1;
 Mat dst;

dst; float data[2][5] = {{11,11,11,11,11},{11,11,11,11,11}}; float kernel[2][2] = {{2,2},{2,2}};

{{2,2},{2,2}}; Mat src = Mat(2, 5, CV_32FC1, &data); Mat ker = Mat(2, 2, CV_32FC1, &kernel);

&kernel); filter2D(src, dst, ddepth , ker,anchor); cout << dst << endl;

endl; char c; scanf("%c",&c);

scanf("%c",&c);

Implement imfilter(matlab) with OpenCV

Hello,

I am trying to port matlab code to c++ with opencv. I could import most source code but I had serious problems with the imfilter function. I was trying to use the filter2d function for c++, but It doesn't get same results between among themselves. What is the difference? How I could get the same result? The source code is very simple.....

    //src_gray has one channel
    //C++ code
filter2D(src_gray, dst,-1, kernel);

    //Matlab code 
    dst = imfilter(src_gray,kernel)

Inputs: src_gray=

11    11    11    11    11
11    11    11    11    11

kernel =

 2     2
 2     2

output:

Matlab:

ans =

88    88    88    88    44
44    44    44    44    22

C++: [88 88 88 88 88; 88 88 88 88 88]

My c++ code:

/// Initialize arguments for the filter
Point anchor( -1, -1 );
double delta = 0;
int ddepth = -1;
Mat dst;

float data[2][5] = {{11,11,11,11,11},{11,11,11,11,11}};
float kernel[2][2] = {{2,2},{2,2}};

Mat src = Mat(2, 5, CV_32FC1, &data);
Mat ker = Mat(2, 2, CV_32FC1, &kernel);

filter2D(src, dst, ddepth , ker,anchor);
cout << dst << endl;

char c;
scanf("%c",&c);

Implement imfilter(matlab) with OpenCV

Hello,

I am trying to port matlab code to c++ with opencv. I could import most source code but I had serious problems with the imfilter function. I was trying to use the filter2d function for c++, but It doesn't get same results between among themselves. What is the difference? How I could get the same result? The source code is very simple.....

    //src_gray has one channel
    //C++ code
filter2D(src_gray, dst,-1, kernel);

    //Matlab code 
    dst = imfilter(src_gray,kernel)

Inputs: src_gray=

11    11    11    11    11
11    11    11    11    11

kernel =

 2     2
 2     2

output:

Matlab:

ans =

88    88    88    88    44
44    44    44    44    22

C++: C++:

[88 88 88 88 88;
88 88 88 88 88]

88; 88 88 88 88 88]

My c++ code:

/// Initialize arguments for the filter
Point anchor( -1, -1 );
double delta = 0;
int ddepth = -1;
Mat dst;

float data[2][5] = {{11,11,11,11,11},{11,11,11,11,11}};
float kernel[2][2] = {{2,2},{2,2}};

Mat src = Mat(2, 5, CV_32FC1, &data);
Mat ker = Mat(2, 2, CV_32FC1, &kernel);

filter2D(src, dst, ddepth , ker,anchor);
cout << dst << endl;