Take the 2-minute tour ×

What is one filter matrix equivalent to applying [1 1 1] twice on an image using imfilter with parameter 'full'? Would it still be a 1x3 matrix?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

convolution is associative, which means (f*g)*h = f*(g*h). So instead of

r = conv(conv(x, [1,1,1]), [1,1,1])

you can use the more efficient (since you convolve on the image only once)

asd = conv([1,1,1], [1,1,1]);
r = conv(x, asd)

where the new function is [1 2 3 2 1], which however is not of the same size of the original filter.

share|improve this answer
Ah gotcha! why 1 2 3 2 1 and not 0 2 3 2 0? Thanks! –  ishali Nov 8 '12 at 10:41
well, if you figure it graphically the 1s are when only the extremities overlap, the 2s are when two elements overlap and the 3 is when the functions completely overlap –  Luca Cavazzana Nov 8 '12 at 10:54
Unless you use the same parameter, which returns an output with the same size of the first parameter, which gives you [2,3,2] (which is equivalent to [0,2,3,2,0]). –  Luca Cavazzana Nov 8 '12 at 11:00
add comment

The full parameter tells the filter function to return an image of the same size of the filtered image. You can apply the same filter any amount of times, but if you use full every time, the size should not change.

share|improve this answer
Thanks for the response. I was wondering though, instead of convolving twice with [1 1 1], what convolution filter can we use just once? –  ishali Nov 8 '12 at 10:09
add comment

Your Answer


