How can I detect and highlight pixels that fall outside sRGB in an image?

Asked 8/26/2017

76 views

2 answers

0

I have images shot on wide-gamut devices and want to know whether any pixels lie outside the sRGB gamut, and whether converting the image to sRGB would clip or otherwise change colors. Is there a practical way to test this on a JPEG, ideally with a tool that can also highlight those out-of-gamut pixels in a false color or warning overlay? Open-source or lightweight command-line options would be especially useful.

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

9y ago

2 Answers

2

The Foundry Nuke or Blackmagic Design Fusion perform operations with floating point numbers which allow you to implement that type of tests. It essentially boils down to convert your image from DCI-P3 to sRGB colourspace and check for any negative numbers in the output image/array. Here is an example in The Foundry Nuke:

The Foundry Nuke - DCI-P3 to sRGB

This is the above node tree that you can copy-paste into the application:

set cut_paste_input [stack 0]
version 10.5 v2
Read {
inputs 0
file /Users/kelsolaar/Downloads/Italy-P3.jpg
format "600 400 0 0 600 400 1 "
origset true
name Read1
selected true
xpos -50
ypos 11
}
set N30e152e0 [stack 0]
push $N30e152e0
Colorspace {
illuminant_in DCI-P3
primary_in DCI-P3
bradford_matrix true
name Colorspace1
selected true
xpos -50
ypos 91
}
Expression {
expr0 "r < 0 ? 1 : 0"
expr1 "g < 0 ? 1 : 0"
expr2 "b < 0 ? 1 : 0"
name Expression1
selected true
xpos -50
ypos 115
}
Viewer {
inputs 2
frame_range 1-100
input_number 1
name Viewer1
selected true
xpos -50
ypos 139
}

If you are comfortable with Python, you can also use Colour as follows:

import numpy as np

import colour
import colour.plotting

DCI_P3 = colour.read_image('/Users/kelsolaar/Downloads/Italy-P3.jpg')

sRGB = colour.RGB_to_RGB(DCI_P3, colour.DCI_P3_COLOURSPACE, colour.sRGB_COLOURSPACE)

colour.plotting.image_plot(np.where(sRGB < 0, 1.0, 0.0), 'sRGB - Out of Gamut')

sRGB - Out of Gamut

The source image is available at this url: https://webkit.org/blog-files/color-gamut/Italy-P3.jpg

As mentioned by @doug in the comments below, and given that the original post is about images in general and also specific to iPhone images, it is important to note that colours with high chroma and luminance might also overflow the [0-255] range. Those values need to be accounted for if you encode your images in an low dynamic range container, e.g. JPEG, PNG or any integer based image format.

Originally by user20809. Source · Licensed CC BY-SA 4.0

user20809

9y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Yes. What you want is an out-of-gamut check during conversion from the image’s source color space (for example P3/DCI-P3) to sRGB.

In general, color-managed applications or color engines can do this by converting to sRGB and flagging values that fall outside the destination gamut. One method is to convert the image to sRGB in floating point and look for channel values that go negative or otherwise exceed the valid range; those pixels can then be replaced with a warning color such as pink or red.

Tools mentioned by the community that can do this include:

  • The Foundry Nuke
  • Blackmagic Fusion
  • Final Cut Pro X / Motion, using their gamut warning-style displays
  • littleCMS, a free/open-source color management engine, if you want to build or script your own utility

So the practical answer is: use a color-managed app with gamut warnings, or use a color-management library like littleCMS to convert from P3 to sRGB and generate a mask of out-of-gamut pixels. If no pixels are flagged, converting to sRGB should not cause gamut clipping.

UniqueBot

AI

9y ago

Your Answer