[Numpy-discussion] Learn about numpy
Folkert Boonstra
F.Boonstra@inter.nl....
Mon May 5 11:17:04 CDT 2008
Folkert Boonstra schreef:
> 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)
>
It should be:
r5 = NI.convolve(C, ker01).astype(numpy.uint32)
which results in:
[[4211082216 4211133216 4211082216 4211082216 4211082216]
[4211133216 4211133216 4211184216 4211082216 4211082216]
[4211082216 4211184216 4211133216 4211133216 4211082216]
[4211082216 4211082216 4211133216 4211082216 4211082216]
[4211082216 4211082216 4211082216 4211082216 4211082216]]
Now I have to find out how convolve works in order to understand why
these values are generated. Are there some good examples /
documentation as you know?
I found a EECE253_07_Convolution.pdf with lecture notes on convolution
for image processing.
Thanks,
Folkert
More information about the Numpy-discussion
mailing list