2009/10/21 Stéfan van der Walt firstname.lastname@example.org
2009/10/21 Ralf Gommers email@example.com:
Fixed in my asgrey branch: http://github.com/rgommers/scikits.image/tree/asgrey I sent Stefan a pull request but grab it there if you need it now.
If you only have grey-scale images setting as_grey to False should do the right thing as well.
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
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 = imread(os.path.join(data_dir, 'lena.png'), flatten=True) lena.shape