Re: Bug in io.ImageCollection
On Wed, Oct 21, 2009 at 1:32 PM, SirVer <sirver@gmx.de> wrote:
On a side note, can't we get a real bug tracker somewhere?
This one should do the job right? At least for now.
http://github.com/stefanv/scikits.image/issues
--- I have a selection of grayscale (8bit) tifs in a directory.
In [14]: k = io.ImageCollection("calib/*.tif", True)
In [15]: k[0].dtype Out[15]: dtype('uint8')
In [16]: k = io.ImageCollection("calib/*.tif", as_grey=True)
In [17]: k[0].dtype Out[17]: dtype('float32') --- But the docs say: as_grey : bool, optional If True, convert the input images to grey-scale. This does not affect images that are already in a grey-scale format.
Obviously the image data type gets converted though.
Thanks for testing Holger. I wrote the docstring based on what I thought pil_imread was doing. Obviously I was wrong. This is the desired behavior imho, so I'll come up with a patch for pil_imread. Cheers, Ralf
Cheers, Holger
On Wed, Oct 21, 2009 at 2:47 PM, Ralf Gommers <ralf.gommers@googlemail.com>wrote:
On Wed, Oct 21, 2009 at 1:32 PM, SirVer <sirver@gmx.de> wrote:
On a side note, can't we get a real bug tracker somewhere?
This one should do the job right? At least for now.
http://github.com/stefanv/scikits.image/issues
--- I have a selection of grayscale (8bit) tifs in a directory.
In [14]: k = io.ImageCollection("calib/*.tif", True)
In [15]: k[0].dtype Out[15]: dtype('uint8')
In [16]: k = io.ImageCollection("calib/*.tif", as_grey=True)
In [17]: k[0].dtype Out[17]: dtype('float32') --- But the docs say: as_grey : bool, optional If True, convert the input images to grey-scale. This does not affect images that are already in a grey-scale format.
Obviously the image data type gets converted though.
Thanks for testing Holger.
I wrote the docstring based on what I thought pil_imread was doing. Obviously I was wrong. This is the desired behavior imho, so I'll come up with a patch for pil_imread.
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. Cheers, Ralf
Cheers, Ralf
Cheers, Holger
Hey Ralf 2009/10/21 Ralf Gommers <ralf.gommers@googlemail.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? 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? Cheers Stéfan
2009/10/21 Stéfan van der Walt <stefan@sun.ac.za>
Hey Ralf
2009/10/21 Ralf Gommers <ralf.gommers@googlemail.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
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?
lena = imread(os.path.join(data_dir, 'lena.png'), dtype="float32") lena.shape (128, 128, 3) lena.dtype
lena = imread(os.path.join(data_dir, 'lena.png'), flatten=True) lena.shape (128, 128) lena.dtype
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: dtype('float32') dtype('float32') Cheers, Ralf
Cheers Stéfan
2009/10/21 Ralf Gommers <ralf.gommers@googlemail.com>:
There is a dtype argument already, you merged my patch for that, commit 44679c7aae5d6b3747c88d46756a3dc96c9a727f.
Oh yes, of course :) My point remains, however, that the default for dtype may have to be changed for consistency. Currently, you have to read the docs to figure out what type will be returned, and I feel that element of surprise can be eliminated simply by specifying the default dtype=float or dtype=np.uint8. Cheers Stéfan
2009/10/21 Stéfan van der Walt <stefan@sun.ac.za>
2009/10/21 Ralf Gommers <ralf.gommers@googlemail.com>:
There is a dtype argument already, you merged my patch for that, commit 44679c7aae5d6b3747c88d46756a3dc96c9a727f.
Oh yes, of course :)
My point remains, however, that the default for dtype may have to be changed for consistency.
Don't think I would agree with that. dtype=None is consistent with how NumPy does this. See for example np.array / np.asarray. Currently, you have to read the docs to
figure out what type will be returned, and I feel that element of surprise can be eliminated simply by specifying the default dtype=float or dtype=np.uint8.
The returned type by default is the type the image was saved as. To me that is the only thing that makes sense. The only thing you have to look up in the docs is what dtype you get when specifying flatten=True. Since you explicitly ask for color -> grey-scale conversion, a sensible type has to be chosen if it's not specified. The smallest type that makes sense is float32. Cheers, Ralf
Cheers Stéfan
2009/10/21 Ralf Gommers <ralf.gommers@googlemail.com>:
Currently, you have to read the docs to figure out what type will be returned, and I feel that element of surprise can be eliminated simply by specifying the default dtype=float or dtype=np.uint8.
The returned type by default is the type the image was saved as. To me that is the only thing that makes sense.
Thanks, that's a convincing argument. Cheers Stéfan
participants (2)
-
Ralf Gommers
-
Stéfan van der Walt