Convolution using convn does not give expected result

Dear all,
I am trying to use a kernel with values which should decrease the values in 3D array that you use. However, when I use convn and 'same', this leads to a plateau with a much higher value as the maximum value of the kernel. Am I using the wrong way to calculate the convolution, or what is happening?
load('s.mat')
A=ones(110,110,110);
C_con=convn(A,s_full,'same');
figure; surf(C_con(:,:,50));

 采纳的回答

There's no reason to think convolution in general won't increase the values. As a trivial example:
A=ones(5);
B=convn(A,2,'same')
B = 5×5
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

4 个评论

But if (almost) all the values are 1.61 or lower (stated in the 11x11x11 array of s.mat), than it is weird that its convolution becomes 5.1?
Not at alll. Here's a revised example with even lower kernel values
A=ones(10);
B=convn(A,[1,1,1,1,1],'same')
B = 10×10
3 4 5 5 5 5 5 5 4 3 3 4 5 5 5 5 5 5 4 3 3 4 5 5 5 5 5 5 4 3 3 4 5 5 5 5 5 5 4 3 3 4 5 5 5 5 5 5 4 3 3 4 5 5 5 5 5 5 4 3 3 4 5 5 5 5 5 5 4 3 3 4 5 5 5 5 5 5 4 3 3 4 5 5 5 5 5 5 4 3 3 4 5 5 5 5 5 5 4 3
Now, if you had normalized the sum of the kernel, that would be a different story:
B=convn(A,[1,1,1,1,1]/5,'same')
B = 10×10
0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000
Ah okay, then the values of the convolution are probably correct. Then the other question, why do I get a ''plateau''? I would expect, since the kernel itself has a sort of Gaussian shape, I would the convolution to also have this kind of shape. If I use a sphere, it looks like this:
I would expect a more smoother shape, with just one peak and not a plateau. How does this work?
You seem to be under the impression that convn(A,B) should always have the shape of B, but convolution is commutative, i.e., convn(A,B)= conv(B,A), so how can the shape of the result have more to do with B than with A? I could just as easily view A as the kernel here, so shouldn't the shape follow A rather than B?

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

产品

版本

R2020a

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by