OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 18 Oct 2018 07:53:57 -0500Laplace matlab opencv differenceshttp://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/ Hello
I wanted to implement the imfilter with the Laplace option (Sobel option worked perfectly) but I it gives a totally different result.
While in the Sobel option both filter2d and the Sobel itself gives me the same result in case of of Laplace the results are different from Matlab
For the Laplace implementation I used:
Mat LAP = (Mat_<double>(3,3) << 1/6, 2/3, 1/6, 2/3, -10/3, 2/3, 1/6, 2/3, 1/6);
And then used the 2D filter:
filter2D(red1,LAP_CONV,CV_64F,LAP);
And the results are totally different
Moreover when I use
Laplacian(red1,LAP_CONV,CV_64F);
Only on my ROI the results are pretty much the same as if I used Matlab on the whole image
And yes I know that the matrixes for Laplace in OPENCV and Matlab are different
The result was checked by std squared
Thanks in advanced for all your helpThu, 18 Oct 2018 03:29:00 -0500http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/Comment by berak for <p>Hello
I wanted to implement the imfilter with the Laplace option (Sobel option worked perfectly) but I it gives a totally different result.
While in the Sobel option both filter2d and the Sobel itself gives me the same result in case of of Laplace the results are different from Matlab
For the Laplace implementation I used:</p>
<pre><code>Mat LAP = (Mat_<double>(3,3) << 1/6, 2/3, 1/6, 2/3, -10/3, 2/3, 1/6, 2/3, 1/6);
</code></pre>
<p>And then used the 2D filter:</p>
<pre><code>filter2D(red1,LAP_CONV,CV_64F,LAP);
</code></pre>
<p>And the results are totally different</p>
<p>Moreover when I use </p>
<pre><code>Laplacian(red1,LAP_CONV,CV_64F);
</code></pre>
<p>Only on my ROI the results are pretty much the same as if I used Matlab on the whole image
And yes I know that the matrixes for Laplace in OPENCV and Matlab are different</p>
<p>The result was checked by std squared</p>
<p>Thanks in advanced for all your help</p>
http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201391#post-id-201391<strike>so you need to flip(kernel, -1)</strike>Thu, 18 Oct 2018 04:34:12 -0500http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201391#post-id-201391Comment by berak for <p>Hello
I wanted to implement the imfilter with the Laplace option (Sobel option worked perfectly) but I it gives a totally different result.
While in the Sobel option both filter2d and the Sobel itself gives me the same result in case of of Laplace the results are different from Matlab
For the Laplace implementation I used:</p>
<pre><code>Mat LAP = (Mat_<double>(3,3) << 1/6, 2/3, 1/6, 2/3, -10/3, 2/3, 1/6, 2/3, 1/6);
</code></pre>
<p>And then used the 2D filter:</p>
<pre><code>filter2D(red1,LAP_CONV,CV_64F,LAP);
</code></pre>
<p>And the results are totally different</p>
<p>Moreover when I use </p>
<pre><code>Laplacian(red1,LAP_CONV,CV_64F);
</code></pre>
<p>Only on my ROI the results are pretty much the same as if I used Matlab on the whole image
And yes I know that the matrixes for Laplace in OPENCV and Matlab are different</p>
<p>The result was checked by std squared</p>
<p>Thanks in advanced for all your help</p>
http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201394#post-id-201394oh, right missed it ;)Thu, 18 Oct 2018 04:45:11 -0500http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201394#post-id-201394Comment by ilia for <p>Hello
I wanted to implement the imfilter with the Laplace option (Sobel option worked perfectly) but I it gives a totally different result.
While in the Sobel option both filter2d and the Sobel itself gives me the same result in case of of Laplace the results are different from Matlab
For the Laplace implementation I used:</p>
<pre><code>Mat LAP = (Mat_<double>(3,3) << 1/6, 2/3, 1/6, 2/3, -10/3, 2/3, 1/6, 2/3, 1/6);
</code></pre>
<p>And then used the 2D filter:</p>
<pre><code>filter2D(red1,LAP_CONV,CV_64F,LAP);
</code></pre>
<p>And the results are totally different</p>
<p>Moreover when I use </p>
<pre><code>Laplacian(red1,LAP_CONV,CV_64F);
</code></pre>
<p>Only on my ROI the results are pretty much the same as if I used Matlab on the whole image
And yes I know that the matrixes for Laplace in OPENCV and Matlab are different</p>
<p>The result was checked by std squared</p>
<p>Thanks in advanced for all your help</p>
http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201393#post-id-201393Its symmetrical (and try it anyway same answer :) )Thu, 18 Oct 2018 04:42:04 -0500http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201393#post-id-201393Comment by ilia for <p>Hello
I wanted to implement the imfilter with the Laplace option (Sobel option worked perfectly) but I it gives a totally different result.
While in the Sobel option both filter2d and the Sobel itself gives me the same result in case of of Laplace the results are different from Matlab
For the Laplace implementation I used:</p>
<pre><code>Mat LAP = (Mat_<double>(3,3) << 1/6, 2/3, 1/6, 2/3, -10/3, 2/3, 1/6, 2/3, 1/6);
</code></pre>
<p>And then used the 2D filter:</p>
<pre><code>filter2D(red1,LAP_CONV,CV_64F,LAP);
</code></pre>
<p>And the results are totally different</p>
<p>Moreover when I use </p>
<pre><code>Laplacian(red1,LAP_CONV,CV_64F);
</code></pre>
<p>Only on my ROI the results are pretty much the same as if I used Matlab on the whole image
And yes I know that the matrixes for Laplace in OPENCV and Matlab are different</p>
<p>The result was checked by std squared</p>
<p>Thanks in advanced for all your help</p>
http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201388#post-id-201388Yes I need convolution its default option as my imfilter function is:
ILAP = imfilter(lm, h, 'replicate', 'conv');
Where I took the h from
h = fspecial('laplacian');Thu, 18 Oct 2018 03:51:47 -0500http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201388#post-id-201388Comment by berak for <p>Hello
I wanted to implement the imfilter with the Laplace option (Sobel option worked perfectly) but I it gives a totally different result.
While in the Sobel option both filter2d and the Sobel itself gives me the same result in case of of Laplace the results are different from Matlab
For the Laplace implementation I used:</p>
<pre><code>Mat LAP = (Mat_<double>(3,3) << 1/6, 2/3, 1/6, 2/3, -10/3, 2/3, 1/6, 2/3, 1/6);
</code></pre>
<p>And then used the 2D filter:</p>
<pre><code>filter2D(red1,LAP_CONV,CV_64F,LAP);
</code></pre>
<p>And the results are totally different</p>
<p>Moreover when I use </p>
<pre><code>Laplacian(red1,LAP_CONV,CV_64F);
</code></pre>
<p>Only on my ROI the results are pretty much the same as if I used Matlab on the whole image
And yes I know that the matrixes for Laplace in OPENCV and Matlab are different</p>
<p>The result was checked by std squared</p>
<p>Thanks in advanced for all your help</p>
http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201386#post-id-201386take a look at the [filter2D](https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga27c049795ce870216ddfb366086b5a04) docs again (convolution vs. correlation)Thu, 18 Oct 2018 03:32:51 -0500http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201386#post-id-201386Answer by berak for <p>Hello
I wanted to implement the imfilter with the Laplace option (Sobel option worked perfectly) but I it gives a totally different result.
While in the Sobel option both filter2d and the Sobel itself gives me the same result in case of of Laplace the results are different from Matlab
For the Laplace implementation I used:</p>
<pre><code>Mat LAP = (Mat_<double>(3,3) << 1/6, 2/3, 1/6, 2/3, -10/3, 2/3, 1/6, 2/3, 1/6);
</code></pre>
<p>And then used the 2D filter:</p>
<pre><code>filter2D(red1,LAP_CONV,CV_64F,LAP);
</code></pre>
<p>And the results are totally different</p>
<p>Moreover when I use </p>
<pre><code>Laplacian(red1,LAP_CONV,CV_64F);
</code></pre>
<p>Only on my ROI the results are pretty much the same as if I used Matlab on the whole image
And yes I know that the matrixes for Laplace in OPENCV and Matlab are different</p>
<p>The result was checked by std squared</p>
<p>Thanks in advanced for all your help</p>
http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?answer=201403#post-id-201403well you already know, that opencv != matlab, but they're using a [different kernel](https://github.com/opencv/opencv/blob/master/modules/imgproc/src/deriv.cpp#L813-L817) than yours:
float K[2][9] =
{
{ 0, 1, 0, 1, -4, 1, 0, 1, 0 },
{ 2, 0, 2, 0, -8, 0, 2, 0, 2 }
};
Mat kernel(3, 3, CV_32F, K[ksize == 3]);
if( scale != 1 )
kernel *= scale;
filter2D( _src, _dst, ddepth, kernel, Point(-1, -1), delta, borderType );Thu, 18 Oct 2018 07:31:46 -0500http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?answer=201403#post-id-201403Comment by ilia for <p>well you already know, that opencv != matlab, but they're using a <a href="https://github.com/opencv/opencv/blob/master/modules/imgproc/src/deriv.cpp#L813-L817">different kernel</a> than yours:</p>
<pre><code> float K[2][9] =
{
{ 0, 1, 0, 1, -4, 1, 0, 1, 0 },
{ 2, 0, 2, 0, -8, 0, 2, 0, 2 }
};
Mat kernel(3, 3, CV_32F, K[ksize == 3]);
if( scale != 1 )
kernel *= scale;
filter2D( _src, _dst, ddepth, kernel, Point(-1, -1), delta, borderType );
</code></pre>
http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201408#post-id-201408I took my matrix from Matlab:
fspacial('laplacian');
alpha = p2;
alpha = max(0,min(alpha,1));
h1 = alpha/(alpha+1); h2 = (1-alpha)/(alpha+1);
h = [h1 h2 h1;h2 -4/(alpha+1) h2;h1 h2 h1];
Where p2 by default equals 0.2Thu, 18 Oct 2018 07:53:57 -0500http://answers.opencv.org/question/201385/laplace-matlab-opencv-differences/?comment=201408#post-id-201408