Vision: Load gray images

Created on 24 Feb 2017  路  5Comments  路  Source: pytorch/vision

How to load gray image in torch vision. I find that folder.py only open image as RGB format:
return Image.open(path).convert('RGB')

Most helpful comment

But the user can provide it's own loader function, so the user could provide his specific loader that only loads grayscale images.

All 5 comments

I think it should still open a grayscale image, and then convert it to RGB. You could just slice only the first slice along the channel dimension and give that to your network. But we should support that, so I'm leaving the issue open.

But the user can provide it's own loader function, so the user could provide his specific loader that only loads grayscale images.

Is this something we still want to support? I think this can be achieved by either a custom loader or a transform i.e. PIL.ImageOps.grayscale

I had a quick look, it's actually quite difficult to determine if an image is grayscale with PIL (in an efficient manner). If the image is saved correctly as a grayscale single-channel image, PIL will have a mode L, but if the image is saved as RGB with each channel replicated, it will display correctly and PIL will load it with mode RGB.

Given that the user can provide its own loader, or could use a transform to perform the conversion, I think it's better to close this issue. Feel free to comment if you think it should be reopened

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carlocab picture carlocab  路  3Comments

zhang-zhenyu picture zhang-zhenyu  路  3Comments

datumbox picture datumbox  路  3Comments

ibtingzon picture ibtingzon  路  3Comments

Linardos picture Linardos  路  4Comments