# Is image padding really necessary while using a filter?

I do know that we must pad an image while using a filter. But what I am suggesting is that is it really necessary? Can't we just calculate at run time if the current cell/pixel is an edge cell/pixel and then use the padding value directly over there. It might add an overhead to the function but so does the entire padding function.

Only reason I think the padding function should be used is if the padded version of original image is going to be used in many different function which will overtake the overhead of dynamically calculating the edge cell/pixel values(which might never occur). Am I wrong?

• Welcome to SE.DSP! It depends how you are calculating the filtering. If you are using an FFT, then you must pad, otherwise you'll get "time aliasing" from the use of circular convolution by the FFT. If your image is $N\times M$ and your filter kernel is $P \times Q$ then your padding must be at least $(N+P-1) \times (M+Q-1)$ to get the expected linear convolution result. – Peter K. May 19 '17 at 15:12