How to convolve 2d signal with a 1D kernel without using loops in matlab?
I have an image. I want to convolve it. I have different type of kernels for both x and y directions. In the function con(u, v)
we can only specify one vector and we have to use loops. For conv2(A, B)
we have to specify a composite kernel. I want to approximate 2d convolution with a开发者_如何学C series of 1D convolutions.
You can use CONV2 without problems.
For example, with one 1D filter being firstFilter = [1 1 1]/3
, and the other 1D filter being secondFilter = [1 0 1]'/2
, you can write the following:
out = conv2( conv2( yourImage, firstFilter, 'same'), secondFilter, 'same');
精彩评论