2009/10/21 Stéfan van der Walt
<stefan@sun.ac.za>
Hey Ralf
2009/10/21 Ralf Gommers <ralf.gommers@googlemail.com>:
Seeing the problem Holger reported makes me think that imread's
behaviour is rather counter-intuitive. Should we not introduce a
dtype flag, so that the outcome type is always as expected?
There is a dtype argument already, you merged my patch for that, commit 44679c7aae5d6b3747c88d46756a3dc96c9a727f.
I.e.
imread('x.png') -> (uint8, uint8, uint8, ...)
imread('x.png', flatten=True) -> uint8
imread('x.png', flatten=True, dtype=float) -> float
imread('x.png', dtype=float) -> (float, float, float, ...)
When it comes to dtypes, surprises are seldom good.
What do you think?
I think a "flatten" keyword is useful, and float32 is a reasonable default. imread should just not try to flatten images that are already flat.
Note that flatten does not only change the dtype, but also does color -> grey-scale correctly. i.e. it returns a 2-D instead of 3-D array:
>>> lena = imread(os.path.join(data_dir, 'lena.png'), dtype="float32")
>>> lena.shape
(128, 128, 3)
>>> lena.dtype
dtype('float32')
>>> lena = imread(os.path.join(data_dir, 'lena.png'), flatten=True)
>>> lena.shape
(128, 128)
>>> lena.dtype
dtype('float32')
Cheers,
Ralf
Cheers
Stéfan