[Numpy-discussion] Learn about numpy

Nadav Horesh nadavh@visionsense....
Mon May 5 12:15:35 CDT 2008



I think you have a problem of overflow in r5: You may better use utin64 instead of uint32.

  Nadav.

-----הודעה מקורית-----
מאת: numpy-discussion-bounces@scipy.org בשם Folkert Boonstra
נשלח: ב 05-מאי-08 19:17
אל: Discussion of Numerical Python
נושא: Re: [Numpy-discussion] Learn about numpy
 
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

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 3885 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080505/63bd6156/attachment.bin 


More information about the Numpy-discussion mailing list