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

Multi-channel images get truncated to 3 channels #3160

Closed
edowson opened this issue Jun 7, 2018 · 4 comments
Closed

Multi-channel images get truncated to 3 channels #3160

edowson opened this issue Jun 7, 2018 · 4 comments
Labels

Comments

@edowson
Copy link

edowson commented Jun 7, 2018

What did you do?

Several Deep Learning Framework Libraries (.e.g PyTorch's TorchVision), Image Processing libraries (.e.g skimage) and machine learning data augmentation libraries (e.g. Augmenter) internally rely on the PIL to perform image transformations.

You can have a situation where in a Semantic Segmentation problem, you have a 3-ch RGB input image, but have a 10-ch mask with each individual channels containing a binary mask of the classes found in the RGB image.

Another situation is when you deal with Geospatial Images, where a TIFF file can contain many channels (8-ch M-Band, 8-ch A-Band) of information corresponding to different spectral bands, for multispectral and hyper-spectral images.

If you use PIL to perform any type of transform, e.g. rescale, it truncates a multi-channel image to a 3-channel image.

There is a related issue #1888, related to PIL not being able to handle high-bit depth images.

What did you expect to happen?

I expected PIL to be able to handle multi-channel images.

What actually happened?

Any multi-channel image processed by the PIL library gets truncated to 3-channels.

What versions of Pillow and Python are you using?

Pillow-5.0.0
Python-3.6.4

The attached file is a binary mask containing 10-channels of binary information in the TIFF file format.

6100_2_2.tif.zip

This is how the original image looks like. It was originally in the TIFF file format, but I've converted it to JPEG format for display.

6100_2_2

Satellite Imagery (C) DigitalGlobe, Inc.

@hugovk
Copy link
Member

hugovk commented Jun 7, 2018

Thanks for the report, please see:

#1888

@edowson
Copy link
Author

edowson commented Jun 7, 2018

One way to handle this is to process each channel individually, in parallel, if the number of channels is greater than 3.

I've had to stop using any image transforms that use PIL, in order to overcome this issue, and resort to using simple transformations using numpy at the moment.

@aclark4life aclark4life added NumPy and removed NumPy labels Jun 30, 2018
@radarhere radarhere changed the title PIL cannot handle multi-channel images, they get truncated to 3 channels by default Multi-channel images get truncated to 3 channels Jul 27, 2019
@radarhere
Copy link
Member

See also #2821

@radarhere
Copy link
Member

Closing in favour of the tracking issue, #1888

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

No branches or pull requests

4 participants