[Numpy-discussion] Learn about numpy

Folkert Boonstra F.Boonstra@inter.nl....
Mon May 5 05:33:10 CDT 2008


Nadav Horesh schreef:
> What you do here is a convolution with 
>
> 0 1 0
> 1 1 1
> 0 1 0
>
> kernel, and thresholding, you can use numpy.numarray.nd_image package:
>
> import numpy.numarray.nd_image as NI
> .
> .
> .
>    ker = array([[0,1,0], [1,1,1],[0,1,0]])
>    result = (NI.convolve(self.bufbw, ker) == 1).astype(uint8)
>
> for nore general cases you can use the function generic_filter in the same package.
>
>    Nadav.
>
>   
Thanks, that works ok! 

However if instead of uint8, uint32 values are used, the result only
contains zeros.
Or am I doing something wrong?
Folkert

import numpy
import numpy.numarray.nd_image as NI

B = numpy.zeros((5,5), dtype=numpy.uint8)
C = numpy.zeros((5,5), dtype=numpy.uint32)

DC = 4278190280
LC = 4278241280

B[:]   = 0
B[1,1] = 1
B[2,2] = 1
C[:]   = DC
C[1,1] = LC
C[2,2] = LC

ker01 = numpy.array([[0,1,0], \
                     [1,1,1], \
                     [0,1,0]])
kerCC = numpy.array([[C[0,0],C[1,1],C[0,0]], \
                     [C[1,1],C[1,1],C[1,1]], \
                     [C[0,0],C[1,1],C[0,0]]]).astype(numpy.uint32)

r1 = NI.convolve(B, ker01).astype(numpy.uint8)
r2 = (NI.convolve(B, ker01) == 1).astype(numpy.uint8)
r3 = NI.convolve(C, kerCC).astype(numpy.uint32)
r4 = (NI.convolve(C, kerCC) == C[0,0]).astype(numpy.uint32)



More information about the Numpy-discussion mailing list