Skip to content

Add support for CMYK -> RGB in decode_jpeg() #6538

Closed
@NicolasHug

Description

@NicolasHug

Asking for a CYMK jpeg file to be converted to RGB by decode_jpeg() currently results in the following error:

from torchvision.io import read_file, decode_jpeg, ImageReadMode

path = "test/assets/fakedata/logos/cmyk_pytorch.jpg"
decode_jpeg(read_file(path), mode=ImageReadMode.RGB)  # ImageReadMode.UNCHANGED would work
RuntimeError: Unsupported color conversion request

This is an important feature to support because the ImageNet dataset has ~20 CMYK images, which means we currently cannot decode ImageNet files with decode_jpeg(): we have to rely on PIL.

According to this comment in our code there should be a way to support this:

/*
* Libjpeg does not support converting from CMYK to grayscale etc. There
* is a way to do this but it involves converting it manually to RGB:
* https://github.com/tensorflow/tensorflow/blob/86871065265b04e0db8ca360c046421efb2bdeb4/tensorflow/core/lib/jpeg/jpeg_mem.cc#L284-L313
*/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions