# [Numpy-discussion] Blurring an Array

Ian Mallett geometrian at gmail.com
Sun Jun 21 03:04:28 EDT 2009

```Hello,

I'm working on a program that will draw me a metallic 3D texture.  I
successfully made a Perlin noise implementation and found that when the
result is blurred in one direction, the result actually looks somewhat like
brushed aluminum.  The plan is to do this for every n*m*3 layer (2D texture)
in the 3D texture.

My solution to this anisotropic blurring looks like:

soften = layerarray.copy()
total = 1
for bluriter in xrange(1,5,1):
soften[:,bluriter:]  += layerarray[:,:-bluriter]
soften[:,:-bluriter] += layerarray[:,bluriter:]
total += 2
soften /= total

Where layerarray is a n*m*3 array, and soften is the array that will be
converted into an image with the other 2D images and saved.

This code successfully blurs the array in the y-direction.  However, it does
not do so the way I would like.  The blur is accomplished by a simple shift,
making the arrays not line up.  This leaves space at the edges.  When the
final soften array is divided by total, those areas are especially dark.
Visually, this is unacceptable, and leads to banding, which is especially
evident if the texture is repeated.  As you can see in this image, which
shows about 6 repeats of the texture,
http://img13.imageshack.us/img13/5789/image1wgq.png, the dark edges are
annoying.

I made sure, of course, that the Perlin noise implementation is tileable.
The solution to my problem is to make the shifted array wrap around so that
its overhang fills in the hole the shift caused it to leave behind.  For
example, to simulate shifting the texture 8 units up with wrap, the first 8
rows should be removed from the top and added to the bottom.  Likewise for
columns if the blur goes in that direction.

I already tried a couple of times at this, and it's not working.  I need a
way to blur soften by column and by row.

Thanks,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090621/1d5eb8d8/attachment.html>
```