[SciPy-user] scipy.signal.convolve2d() clips off part of my image

Travis Oliphant oliphant at ee.byu.edu
Fri Jan 28 15:50:57 EST 2005


Mike Kreiner wrote:

>I posted this message earlier to comp.lang.python, but figured this
>would be a better place to go.
>
>I'm using the convolve2d(image, mask) function from scipy to blur an
>image. The image I'm using is 512 by 384. When I display the image that
>convolve2d returns, the the left-most square of pixels (388 by 388)
>turn out fine, blurred and everything, however the right side of the
>image is all black.
>  
>
Could be a bug.  I'll look into it.  I'm rewriting the convolve2d 
function right now, to be much faster.  

>I've uploaded the practice image to: http://tinypic.com/1g3iox
>The output image is: http://tinypic.com/1g3iv9
>
>here's what I entered at the intereactive window:
>
>  
>
>>>>import scipy
>>>>img = scipy.imread("c:\\practice.jpg",flatten=True)
>>>>img.shape
>>>>        
>>>>
>(384, 512)
>  
>
>>>>mask =
>>>>        
>>>>
>
>(1.0/115)*scipy.array([[2,4,5,4,2],[4,9,12,9,4],[5,12,15,12,5],[4,9,12,9,4],[2,4,5,4,2]])
>
>  
>
>>>>blurredImg = scipy.signal.convolve2d(img, mask)
>>>>scipy.imsave("c:\\blurred.jpg",blurredImg)
>>>>        
>>>>
>
>Also, I noticed that the shape attribute is (384, 512), even though
>windows and my image editor say the image is 512 by 384. Could this
>have something to do with the reason convolve2d() only works right on
>the left-most 388 by 388 pixels? Thanks for any help.
>  
>
No, the two are unrelated.  Scipy's convention is to report the shape of 
an array as (rows, columns).  A lot of images are reported in terms of 
width x height.  But width is the number of columns, and height is the 
number of rows.

So a 512 x 384 (width x height) image would have a shape of 384 rows and 
512 columns --- img.shape = (384, 512)

Thanks for the report.

-Travis






More information about the SciPy-User mailing list