[SciPy-user] Bug in find_objects? (Was: Re: image processing)

Vicent Mas (V+) vmas at carabos.com
Thu Nov 2 09:58:00 CST 2006


El Thursday, 2 de November de 2006 14:22, Gary Ruben escribió:
> Hi Vincent,
> I noticed noone replied to your email so I just tried your script and
> here's the output I get with scipy 0.5.0.2033:
>
> [[0 1 1 0 0 0]
>   [0 1 1 0 1 0]
>   [0 0 0 1 1 1]
>   [0 0 0 0 1 0]]
>
> [[0 1 1 0 0 0]
>   [0 1 1 0 2 0]
>   [0 0 0 2 2 2]
>   [0 0 0 0 2 0]]
> 2
>

Hi Gary,

first of all, I didn't mention which versions of scipy and numpy I'm 
using. Sorry. They are 0.5.1 and 1.0rc1.

The problem is that scipy.ndimage.measurements.label returns an integer 
array with 

In [18]: label_matrix.dtype.num
Out[18]: 5

Notice that if you build an integer array as usual then

In [19]: A = numpy.oldnumeric.array(range(0,5))

In [20]: A.dtype.num
Out[20]: 7

In [21]: B = scipy.array(range(0,5))

In [22]: B.dtype.num
Out[22]: 7

Passing an array like label_matrix to find_objects raises a runtime 
error as explained in my last mail. Passing an array like A to 
find_objects works fine. The problem is not detected in the 
scipy.ndimage tests module because all arrays passed to find_objects 
are like A.

This being said I can reproduce exactly your results after doing a dirty 
trick in the module numpy/oldnumeric/precision.py. Just replace the 
line

typecodes = 
{'Character':'c', 'Integer':'bhil', 'UnsignedInteger':'BHI', 'Float':'fd', 'Complex':'FD'}

by

typecodes = 
{'Character':'c', 'Integer':'bhli', 'UnsignedInteger':'BHI', 'Float':'fd', 'Complex':'FD'}


Although it works for me it is far from being perfect (I think it will 
not work on 64-bits platforms). One of my colleagues has reported the 
bug to numpy this morning, see 
http://projects.scipy.org/scipy/numpy/ticket/370

I hope that my explanations are clear enough (I'm not an expert on data 
types).

Thanks a lot for your answer.

-- 
::

	 \ /	Vicent Mas	http://www.carabos.com
	 0;0	
	/   \	Cárabos Coop.	Enjoy Data
	V   V
	 " "


More information about the SciPy-user mailing list