Help, Image Filters with numpy

Charles G Waldman cgw at alum.mit.edu
Fri Jun 2 16:34:20 EDT 2000


In article <393803A2.9AE23E9C at visionart.com>, Pete Shinners
<pete at visionart.com> wrote:
> i have some image data, greyscale, and i'd like to do some simple filter
> work on it. i'm trying to think of a "most optimized" way to get this
> done. i'm not sure about all the tools that numerical python gives me,
> so i thought i'd ask to see if parts of this are already taken care of.
> 
> say i define a quick soften filter...
> 
> soften = array([[1,2,1], [2,4,2], [1,2,1]])
> 
> how can i quickly/easily apply this to my image which is stored in
> another array? i've been hunting examples that would do this for me, but
> no luck
> 

The name for the operation you're looking
for is convolution.  Any book on digital image
processing will describe this - the book of 
Russ is an good general reference.

Numeric Python has a "convolve" method but it 
unfortunately only supports 1D convolution.  However
the filter coefficients you give describe a separable
kernel - i.e. the 2D convolution is a composition of
2 1D convolutions, in the row and column directions
(this is not true for all convolution kernels).

Also note that the Python Imaging Library ("PIL") has
builtin support for convolution filters.

Finally, if you are convolving with very large kernels,
it is more efficient to use Fourier transform techniques.




More information about the Python-list mailing list