-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keras issue for loading uint16 (16 bits) images by ImageDataGenerator #13023
Comments
This seems like an issue for Pillow and not Keras. Keras uses Pillow to load images and Pillow currently does not support multi-channel images with more than 8 bits. However, it does support higher bit-depth single-channel images. Please see python-pillow/Pillow#1888 |
You are correct about the Pillow issue with multi-channel images in 16 bits. However, this is an issue with Keras too as Keras fails loading images! Keras can provide the ability to load images using OpenCV or Scipy which can resolve this issue. Hopefully either |
I'm experiencing this issue with Keras too. Keras (& Pillow) should at least provide a warning. However, Pillow is able to open my uint16 tiff. When the file is opened with Keras the returned object type is PIL.Image.Image, but when the file is opened with Pillow directly the returned object type is PIL.TiffImagePlugin.TiffImageFile. It's like the Keras version of Pillow is not using the tiff image plugin. I've asked a question here https://stackoverflow.com/questions/58358169/keras-cant-load-uint16-tiff-images. Update: It seems in my case the keras_preprocessing/image/utils.py |
I agree with @CA4GitHub: this is not only a Pillow issue, as it happens also for single-channel 16-bit TIFF images; python-pillow/Pillow#1888 explicitly states that Pillow "is able to open higher bit depth images (e.g. I16, I32, or Float32 images) if they are single channel". In fact, as @CA4GitHub rightly states, PIL loads a 16-bit single-channel TIFF file into an And while I am typing this, I am noting keras-team/keras-preprocessing@4e412de If anyone wants to use this before this is released:
|
Bumping this since I'm also having the same problem. The 16-bit images are getting truncated at 255 |
I think this is fixed as of |
keras-preprocessing version 1.1.2 provides support for 16 bit grayscale images however, there is still no support for 16 bit r,g,b images ? The update https://github.com/keras-team/keras-preprocessing/commit/4e412de9f6dda66309f0e0f0a6ab5acd3691967f also seems to suggest this, right? |
Hello. I have been using keras-preprocessing 1.1.2, so in theory this shoudl be fixed, but the problem continues. With this code : it = train_datagen.flow_from_directory("/home/tiago/workspace/aquila/test_16_bit/16bit/", I get min and max values on the generated image in between 0 and 255, no matter if my original images are 8 bit or 16 bit PNG (both cases grayscale) (the second ones with values up to 4096. If it were working correctly the value range should not have been compressed down to max 255. Can anyone confirm that has been solved, and if yes if there is something else I should be looking about to fix it? EDIT: I kind of figured. IF the ImageDataGenerator has the parameter brightness_range set, then it reverts into the problem and all the images are again forcefully squeezed into 8 bit depth. If I leave that parameter out, then it works. |
Please make sure that this is a Bug or a Feature Request and provide all applicable information asked by the template.
If your issue is an implementation question, please ask your question on StackOverflow or on the Keras Slack channel instead of opening a GitHub issue.
System information
You can obtain the TensorFlow version with:
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"
You can obtain the Keras version with:
python -c 'import keras as k; print(k.version)'
Describe the current behavior
The 16 bits images are getting saturated as Keras reads them as 8bits! Anything above 255 will be 255!
Describe the expected behavior
16 bits images should be read properly but it does not!
Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.
Save a 16 bits image and load it by ImageDataGenerator; the results will be between 0 to 255.
Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.
The issue is straight forward and can be easily resolved. Please let me know if you need more info. Also, thank you for the great API. I hope you resolve the issue soon as I do not want to write the whole ImageDataGenerator just because of this issue!
Thank you!
The text was updated successfully, but these errors were encountered: