Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Images colorspace conversion to sRGB #210

Open
cogat opened this issue Mar 10, 2017 · 8 comments
Open

Images colorspace conversion to sRGB #210

cogat opened this issue Mar 10, 2017 · 8 comments

Comments

@cogat
Copy link
Contributor

cogat commented Mar 10, 2017

glamkit-imagetools has a function which converts a given image to the sRGB color space, meaning that images with a different color space can be converted and don't appear too different when the profile is stripped for e.g. thumbnails and IIIF operations.

The question is, when is the right time to do the sRGB conversion? My instinctive answer is: upon thumbnail creation, rather than on upload.

So, let's do that, unless there's a compelling reason to convert the original uploaded image.

@jmurty
Copy link
Contributor

jmurty commented Apr 4, 2017

I agree that we should leave sRGB conversion as late as possible. Aside from the extra complexity of doing this work on upload, unless I misunderstand it is a data-losing operation that I don't think we should apply to original images.

When reviewing the the easy-thumbnails library for inspiration for the IIIF Image API I learned that thumbnails generated for colour images (not black-and-white) are automatically converted by this library into the RGB colourspace. I applied the same approach for the IIIF Image API, see https://github.com/ic-labs/django-icekit/blob/develop/icekit/plugins/iiif/views.py#L202

So in short, the RGB conversion is already being done when needed while leaving the original images intact. I don't think we need to change this approach.

Unless, that is, the glamkit-imagetools does more sophisticated colour space conversion that the basic approach linked above?

@cogat
Copy link
Contributor Author

cogat commented Apr 4, 2017

@jmurty yep I think there's a subtlety here - I used 'colour space' to mean 'colour profile'. Converting (from CMYK) to RGB colourspace isn't the same as converting the embedded colour profile to sRGB, a specific standard defined for consumer monitors. Last I checked (in SFMOMA), EasyThumbnails doesn't do any colour profile conversion, it just strips it in the output to reduce filesize.

It seems to me sRGB profile conversion should be a default of easy-thumbnails (perhaps there is a ticket about it over there?) but it wasn't at SFMOMA time.

@jmurty
Copy link
Contributor

jmurty commented Apr 4, 2017

NOTE: The conversion performed by icekit-imagetools is more sophisticated than the basic RGB colourspace conversion we are already doing. See https://github.com/ixc/icekit-imagetools/blob/develop/imagetools/utils/srgb.py

@cogat
Copy link
Contributor Author

cogat commented Apr 4, 2017

On a quick look through the list, this is the only relevant easy-thumbs ticket (ie converting to sRGB would solve this):
SmileyChris/easy-thumbnails#366

@jmurty
Copy link
Contributor

jmurty commented Apr 4, 2017

Looking at the above, to do full sRGB colour profile conversion (or just retention) we will need to:

  • add sRGB handling to the IIIF Image API implementation, based on the code in icekit-imagetools (though probably adapted to be less reliant of images always being in local files)
  • investigate whether easy-thumbnails does already, or can be made to, do the sRGB conversion/retention for us. If not, we may need to monkey-patch it. The main problem seems to be including the ICC profile when writing the image, e.g. img.save(outfile, icc_profile=SRGB_BYTES

@cogat
Copy link
Contributor Author

cogat commented Jul 11, 2017

easy-thumbnails doesn't do color profile conversion by default, unless it's started doing it since we built SFMOMA.

I propose that we add a THUMBNAIL_PROCESSORS processor that converts images to sRGB using the glamkit-imagetools process, perhaps in the presence of an srgb option.

(There's also this simpler approach from DrMeers: https://stackoverflow.com/questions/11041044/convert-jpg-from-adobergb-to-srgb-using-pil, but it may only work with Adobe RGB source profiles, not arbitrary profiles).

@cogat
Copy link
Contributor Author

cogat commented Jul 11, 2017

Here are 4 examples to illustrate, from https://www.sfmoma.org/artwork/2005.102 . If the file is created with Adobe sRGB the colour looks flat if the profile is stripped (as easy-thumbnails will do) or even if it isn't stripped and viewed on mobile (as mobile devices ignore colour profile). Converting the file to sRGB results in minimal difference on consumer screens if the profile is stripped or ignored.

with Adobe RGB (looks flat on mobile devices)
with adobe rgb

Adobe RGB, profile stripped (looks flat)
adobe rgb profile stripped

with sRGB (looks OK on all devices)
with srgb

sRGB, profile stripped (looks OK on all devices)
srgb profile stripped

@cogat
Copy link
Contributor Author

cogat commented Feb 3, 2020

I have made an easythumbnails image processor based on the util above that converts an image to sRGB colour profile and RGB colour space so that there is the minimum of visual disruption when the colour profile is dropped. Add it to the beginning of THUMBNAIL_PROCESSORS as per https://easy-thumbnails.readthedocs.io/en/latest/ref/processors/#custom-processors.

https://gist.github.com/cogat/fbdfeb099564ef0cdda8491b0d65557c

I think this can replace the default colorspace processor.

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

No branches or pull requests

2 participants