[Numpy-discussion] Blurring an Array
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 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Blurring an Array
On Sun, Jun 21, 2009 at 02:04, Ian Mallett geometr...@gmail.com wrote: 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 Use scipy.ndimage.convolve() and an appropriate convolution kernel. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Blurring an Array
Sounds like it would work, but unfortunately numpy was one of my dependency constraints. I should have mentioned that. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Blurring an Array
On Sun, Jun 21, 2009 at 03:31, Ian Mallett geometr...@gmail.com wrote: Sounds like it would work, but unfortunately numpy was one of my dependency constraints. I should have mentioned that. In that case, use numpy.roll() instead of slicing to get wraparound. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Blurring an Array
This works perfectly! Is there likewise a similar call for Numeric? ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Blurring an Array
On Sun, Jun 21, 2009 at 05:48, Ian Mallett geometr...@gmail.com wrote: This works perfectly! Is there likewise a similar call for Numeric? If Numeric.roll() exists, then yes. Otherwise, you may have to look at the numpy.roll() sources to replicate what it does. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion