# Convolution Border Pixels

## Recommended Posts

Hi everyone, I've been stuck on this problem for over a day now, any comments would be appreciated. From my understanding there are many ways to deal with bordering pixels: Right now I'm using a mask of: [0.5 1 0.5] [1 0 1] [0.5 1 0.5] with a divisor of 3. When I perform this in code on a non-bordering pixel it turns: [0 0 0] [0 255 0] [0 0 0] into [127 255 127] [255 0 255] [127 255 127] and multiplying by the divisor, [42 85 42] [85 0 85] [42 85 42] For a bordering pixel (ie top left corner) a method is to do so by changing: [255 0 0] [0 0 0] [0 0 0] into [0 255 0] [255 127 0] [0 0 0] and multiplying by the divisor, [0 85 0] [85 42 0] [0 0 0] But when I do this in Flash using their convolution filter : http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/filters/ConvolutionFilter.html I get this instead: [212 127 0] [127 42 0] [0 0 0] Notice how the 42 is correct because it is a pixel that has all the neighboring vertices available. But the others are different and I cannot figure out why. I've tried using different masks for the borders but no luck. Also if this continues in flash. As long as a pixel has all available neighbors, it works as expected but the bordering ones are always handled differently. Can someone explain this? Thanks

##### Share on other sites
alvaro    21246
If you do it in your straight-forward way, you'll see that the border of the result is darker than the rest of the image (use an image of a constant color to test this). Basically, you are assuming that the pixels outside of the original image are all black, and this black bleeds in through your filter.

A common technique to avoid this is to reflect the image on all its edges in order to get some sort of continuity at the border. So the image
[A B C]
[D E F]
[G H I]

becomes
E D D E F
B A A B C
B A[A B C]
E D[D E F]
H G[G H I]

If we look at the values beyond the limits of the image in your example,
[255 0 0]
[0 0 0]
[0 0 0]

they can either be this (your interpretation):
0 0 0 0 0
0 0 0 0 0
0 0[255 0 0]
0 0[0 0 0]
0 0[0 0 0]

or this (flash's interpretation):
0 0 0 0 0
0 255 255 0 0
0 255[255 0 0]
0 0[0 0 0]
0 0[0 0 0]

Applying your filter to the latter interpretation should give you the same results as flash.