[Numpy-discussion] Overloading numpy's ufuncs for bettertypecoercion?
Wed Jul 22 09:43:43 CDT 2009
> Although it should be noted that in C/C++,
> the result of uint8+uint8 is int.
But C/C++ works with scalars and often temporary results
are kept in registers.
On the contrary, numpy works with arrays. We cannot expect
to grow from uint8 to uint16 and then uint32 :-D
> For example, the conversion would typically have to be
> performed only once (after loading), no? Then, why not simplify things
> further by adding a dtype= parameter to importImage()? This could even
> default to float32 then.
I think this is the cleanest, easiest, better way to go.
Also, Matlab's imread reads the image in its format (e.g. uint8).
An explicit conversion is needed (e.g. double()) otherwise
all the operations are performed in uint8. Even
i = imread('...');
i = i + 34.5
does not trigger an upcast.
The only difference is that matlab saturates to 0 and 255
instead of wrapping.
More information about the NumPy-Discussion