OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 13 Oct 2018 05:49:45 -0500filter2d vs conv2http://answers.opencv.org/question/201072/filter2d-vs-conv2/The result I get from conversion of conv2 function in matlab is very different from the result I get in opencv using filter2d function.
In opencv in the position of (0,0) I get 1.1175871e-08 while the result I get in matlab is -0.9639
In Matlab:
A = [1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6];
k = [-0.014, -0.45, 0, 0.45, 0.014];
conv2(A, k, 'same');
In opencv/c++:
cv::Mat dst;
float K[5] = {-0.014, -0.45, 0, 0.45, 0.014};
cv::Mat kernel(1, 5, CV_32F, K);
Mat kernel-p(1,5, CV_32F);
cv::flip(kernel, kernel-p, -1);
float test[6][6] = {{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6}};
cv::Mat myMat(3, 4, CV_32FC1, &test);
filter2D(myMat, dst, -1 , kernel , Point( -1, -1 ), 0, BORDER_DEFAULT);
What am I doing wrong in the opencv code?tinahomSat, 13 Oct 2018 05:49:45 -0500http://answers.opencv.org/question/201072/Implementing a kernel convolutionhttp://answers.opencv.org/question/75148/implementing-a-kernel-convolution/ Hi guys..
I am felling a bit stupid asking this question, but I can't seem to come around the issue.
I am trying to implement a contra harmonic filter using the equation given here
[http://masters.donntu.org/2007/kita/gett/library/eng.htm](http://masters.donntu.org/2007/kita/gett/library/eng.htm)
But I seem to be stuck at implementing the Kernel part of the filter..
The way i've coded until now is using 4 for - loop , first two to interate through the image, and second two to iterate through the kernel..
Mat ContraHarmonic(Mat src, int kernel)
{
Mat output = src.clone();
for(int x = 0; x < src.rows; x++)
{
for(int y = 0; y < src.cols; y++)
{
for(int subX = 0; subX < kernel; subX++)
{
for(int subY = 0; subY < kernel ; subY++)
{
output.at<uchar>(x-1+subX,y-1+subY) = 255;
}
}
}
}
imshow("output",output);
waitKey(0);
return output;
}
I know that the formula isn't right at the moment.. But When run this piece of code.. I do not get an output.. I am bit unsure whether I am doing this right, or I am missing some thing.. How do i detect whether the kernel is within the image, and not partly outside? 215Mon, 02 Nov 2015 06:32:02 -0600http://answers.opencv.org/question/75148/