Skip to content
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

Image Preprocessing corrupts some greyscale images #10437

Closed
alexzubiaga opened this issue Jun 14, 2018 · 3 comments
Closed

Image Preprocessing corrupts some greyscale images #10437

alexzubiaga opened this issue Jun 14, 2018 · 3 comments

Comments

@alexzubiaga
Copy link

While training an Inception Model with a mix of color and greyscale images I've noticed that some of the greyscale images were loosing most of the details when loading them with flow_from_directory.

The cause is the RGB conversion from Pillow used in load_img as described in this issue Pillow-2574

In my case the suggested workaround fixed the conversion.

This is the code I've used to handle the RGB conversion:

if img.mode != 'RGB':
    if img.mode == 'I':
        from PIL import ImageMath
        img = ImageMath.eval('im/256', {'im': img})
    img = img.convert('RGB')
@keck-in-space
Copy link

Super super helpful. Thank you!

@alexzubiaga
Copy link
Author

And I thought I was the only one working with greyscale images. Glad to be of help.

@ronz0215
Copy link

Hello,
I have similar issue, I'm using mode 'I' too, however my images are saved as uint16 so scaling by 256 losses too much info. I noticed the numpy array can be a float32...has anyone tried to normalize to 16k?

Also, I'm not super familiar with Python and my understanding is you can't overload classes...so where did you make your changes? Did you make changes to the keras modules in your site-packages dir or is there some other way to make these changes without modifying the downloaded code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants