In one step of image evaluations I need to apply a gaussian blur to pixel data. I do this by folding each pixel with a gaussian folding matrix. This is no problem unless I try to do this with pixels at the border of the image since for example on the left border I can't include the pixels to the left in my folding calculation. There are multiple ways around this that I can think of:

  1. Don't blur pixels without a complete set of neighbours.
  2. Ignore the neighbours that aren't there.
  3. Use the center pixel instead of the pixels that are missing.
  4. Use the pixel at the other side of the image.

Case 2 isn't right in my opinion because it destroys the normalization of the whole folding matrix. I can't use 4. in my case and it doesn't really make sense anyways.

So my question is: How should this problem be handled?


There are a number of different way to do this, and the "right" choice depends on the exact application.

Your option 1 is probably not what you want, but a similar option is to simply return a smaller image, on which the blur is well defined. This is probably the closest you will get to something "fool proof", if you can live with the smaller image.

Your option 2 could work, and is certainly a valid option provided you redo the normalization so it still integrates to 1. I personally prefer this option

Another option is a mirroring boundary condition, so you count some of your pixels twice.

If you look at the Gaussian blur in SciPy, you will see a number of different options, all of which are quite valid from a mathematical point of view.

It really very much depends on your application.

You may want to have a look at the Signal Processing StackExchange, as this is probably more their domain.

  • $\begingroup$ Thank you for your help. It's a bit complicated because I'm not working with rectangular images (can be arbitrary shapes). I will take a look at the links you provided. It was hard to choose the "correct" StackExchange in this case. $\endgroup$
    – Jens
    May 8 '14 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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