DSPRelated.com
Forums

when should I pad image before filtering?

Started by lucy March 25, 2005
I am always confused by the padding for image filtering.

I have an 270x230 "image" and is to be filtered with a 250x250 "filter".

I have made sure that the sum of all filter coefficients sum to be 1.

In Matlab,

sum(sum(filter)) =1.0000,

then I do image filtering:

result=imfilter(image, filter, 'same');

so the result is the also a 270x230 image... since I've used 'same' option, 
...

I am not sure if the result is correct or not...

in fact, I even don't understand when a 270x230 image convolved with a 
250x250 filter, is the result meaningful at all?

Anybody please give me some enlightment?

And Matlab has so many options: such as "replicate", "symmetric", etc:

        X            Input array values outside the bounds of the array
                     are implicitly assumed to have the value X.  When no
                     boundary option is specified, IMFILTER uses X = 0.

        'symmetric'  Input array values outside the bounds of the array
                     are computed by mirror-reflecting the array across
                     the array border.

        'replicate'  Input array values outside the bounds of the array
                     are assumed to equal the nearest array border
                     value.

        'circular'   Input array values outside the bounds of the array
                     are computed by implicitly assuming the input array
                     is periodic.

When do we choose which option?



"lucy" <losemind@yahoo.com> wrote in message 
news:d20avh$p2b$1@news.Stanford.EDU...
>I am always confused by the padding for image filtering. > > I have an 270x230 "image" and is to be filtered with a 250x250 "filter". > > I have made sure that the sum of all filter coefficients sum to be 1. > > In Matlab, > > sum(sum(filter)) =1.0000, > > then I do image filtering: > > result=imfilter(image, filter, 'same'); > > so the result is the also a 270x230 image... since I've used 'same' > option, ... > > I am not sure if the result is correct or not... > > in fact, I even don't understand when a 270x230 image convolved with a > 250x250 filter, is the result meaningful at all? > > Anybody please give me some enlightment? > > And Matlab has so many options: such as "replicate", "symmetric", etc: > > X Input array values outside the bounds of the array > are implicitly assumed to have the value X. When no > boundary option is specified, IMFILTER uses X = 0. > > 'symmetric' Input array values outside the bounds of the array > are computed by mirror-reflecting the array across > the array border. > > 'replicate' Input array values outside the bounds of the array > are assumed to equal the nearest array border > value. > > 'circular' Input array values outside the bounds of the array > are computed by implicitly assuming the input array > is periodic. > > When do we choose which option? > > >
Strange. I really don't understand this: what happens if I have a 270x230 image convolved with a 600x600 filter using Matlab function? result=imfilter(image, filter, 'same')? what happens if I have a 270x230 image convolved with a 100 x 100 filter using the same matlab function? Are these results still correct? I understand the small case: if an image 270x230 convolved with a 3x3 filter, I understand, the image will have false values on its 4 side 1pixel width boundary. All other values should be correct value...
lucy wrote:
> "lucy" <losemind@yahoo.com> wrote in message > news:d20avh$p2b$1@news.Stanford.EDU... > >>I am always confused by the padding for image filtering. >> >>I have an 270x230 "image" and is to be filtered with a 250x250 "filter".
The bit in the middle is almost correct. The rest of the output image will be wrong. Whether this is a problem for you depends on why you are doing this. ...
>>When do we choose which option?
They are all wrong. You use the one which is least wrong, and which that is depends on your input image and what you seek to achieve with it.
> Strange. I really don't understand this: > > what happens if I have a 270x230 image convolved with a > 600x600 filter using Matlab function?
Try it and see.
> what happens if I have a 270x230 image convolved with a 100 x 100 filter > using the same matlab function?
Try it and see.
> Are these results still correct?
"Still" correct; what makes you think any of this is correct?
> I understand the small case: if an image 270x230 convolved with a 3x3 > filter, I understand, the image will have false values on its 4 side 1pixel > width boundary. All other values should be correct value...
Yep. The large filter case is no different (except that it is larger). Regards, Martin -- Regards, Martin Leese E-mail: please@see.Web.for.e-mail.INVALID Web: http://members.tripod.com/martin_leese/