Shan
Shan

Reputation: 19243

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 series of 1D convolutions.

Upvotes: 2

Views: 2139

Answers (1)

Jonas
Jonas

Reputation: 74930

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');

Upvotes: 3

Related Questions