Take the 2-minute tour ×
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It's 100% free, no registration required.

I have the moving-average mask as

   mask = [1 1 1; 1 1 1; 1 1 1];

and then I compute the convolution 3 times

   imageF = conv2(conv2(conv2(originalImage, mask), mask), mask);

I want to know how can I get an equivalent mask to compute the filter with just one convolution

   imageF = conv2(originalImage, equivMask);
share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

Convolution in linear time-invariant system is asociative. So to get the equivalent mask you just need to convolve the kernel with itself twice. This will then then give you a 7x7 kernel:

octave:1> a = [ 1 1 1 ; 1 1 1 ; 1 1 1 ]
a =

   1   1   1
   1   1   1
   1   1   1

octave:2> conv2(a,conv2(a,a))
ans =

    1    3    6    7    6    3    1
    3    9   18   21   18    9    3
    6   18   36   42   36   18    6
    7   21   42   49   42   21    7
    6   18   36   42   36   18    6
    3    9   18   21   18    9    3
    1    3    6    7    6    3    1

octave:3> 

Note that the original mask is not normalised - it has a gain of 9 at DC - so with three convolutions you get an overall gain of 9^3.

Depending on what you're trying to achieve though you might just be better off with a 7x7 Gaussian.

share|improve this answer
    
No, in fact what I meant was conv(conv(conv2(OriginalImage, mask), mask), mask). –  BRabbit27 Nov 11 '12 at 15:57
1  
Yes, that is what I thought you meant, and this is then equivalent to using the 7x7 kernel above. –  Paul R Nov 11 '12 at 16:41
2  
Good answer. I think you should add a sentence about the fact that it is possible due to the fact that convolution is associative. –  Andrey Nov 11 '12 at 17:02
1  
Should this resulting kernel be normalized? –  heltonbiker Nov 11 '12 at 17:24
2  
You can just repeatedly convolve with the original mask. Obviously the kernel will grow by 2 in each dimension for each iteration so after 20 convolutions the kernel will be 41x41. –  Paul R Nov 11 '12 at 19:50
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.