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?
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 precompute the convolution of the two filters and then apply it to each image only once:
tmp_filter = conv([1,1,1], [1,1,1]);
...
r1 = conv(x1, tmp_filter)
r2 = conv(x2, tmp_filter)
where the new filter is [1 2 3 2 1]
, which however is not of the same size of the original filter.


well, if you figure it graphically the
1
s are when only the extremities overlap, the2
s are when two elements overlap and the3
is when the functions completely overlap– CavazNov 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]
).– CavazNov 8 '12 at 11:00 
Note that if you use
same
when convolving the two kernels, the resulting kernel is not equivalent to the composition of the two kernels. You need to usefull
when composing kernels. This is true independently of what mode is used to apply the convolutions to the image. Nov 28 '18 at 14:06
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.

Thanks for the response. I was wondering though, instead of convolving twice with [1 1 1], what convolution filter can we use just once?– ishaliNov 8 '12 at 10:09

This is wrong.
full
causes the output to be larger than the input.same
preserves the size. Also, this answer doesn’t address the question. Nov 28 '18 at 14:03