I'm writing a halftone algorithm, which takes standards RGB intensities in the range of $0-255$ and outputs black and white elements with a corresponding size ratio.

Should I apply a gamma expansion on the input luminance to get the ratio?

I.e. is it correct to do the following?

$\frac{w_\text{white}}{w_\text{white}+w_\text{black}} = (0.299 R + 0.587 G + 0.114 B)^{2.2}$

Should I apply the exponent of $2.2$?


Yes and no. The RGB values are most likely gamma compressed.

Consider gamma calibration images like the one below.

For a well calibrated monitor the gray value should look the same as the pattern of black and white lines.

If you load in the image you will likely find RGB values of $186$.

$(186/255)^{2.2} \approx 0.5$, which means that a halftone pattern of black and white lines of equal width correspond to RGB values of 186.

gamma calibration image

However, the gamma compression applied was more likely the sRGB gamma compression than an overall gamma of $2.2$.

$$ \frac{w_\text{white}}{w_\text{white}+w_\text{black}} = \begin{cases} 12.92V &\text{ if } V \leq 0.0031308 \\ 1.055 V^{1/2.4} + 0.055 &\text{ if } V > 0.0031308 \end{cases} $$

where $V = 0.299R+0.587G+0.114B$

  • 2
    $\begingroup$ "The RGB values are most likely gamma compressed." That's common for 8-bit images, but you need to actually know, not just guess. Monitor calibration is a bit of a red herring nowadays, because applications should be drawing sRGB and the monitor should be interpreting its input as sRGB anyway. $\endgroup$ – Dan Hulme Jan 26 '18 at 14:50
  • 3
    $\begingroup$ A typical display is calibrated to sRGB, not gamma 2.2. So you should use the linear to sRGB or sRGB to linear conversions. And a 50% sRGB value should be 188, not 186. (see Wikipedia article for sRGB which says that a normalized 50% intensity should get an sRGB value of (1.055*0.5^(1/2.4))-0.055 = 0.735358, which is about 187.516 in 8-bit sRGB, hence the logic of encoding it as 188. $\endgroup$ – Wyck Jan 26 '18 at 20:32
  • $\begingroup$ The monitor calibration image is indeed kind of misleading for my argument. It does show that I should perform gamma expansion, but not which one. Am I correct to conclude that most images will likely be encoded with sRGB and I should use the formula provided by @Wyck? ($1.055L^{1/2.4}-0.055$) $\endgroup$ – Tim Kuipers Jan 27 '18 at 16:01
  • 1
    $\begingroup$ Given that you are only doing half-toning, you could probably get away with a much cheaper approximation of gamma/sRGB such as using a square root. $\endgroup$ – Simon F Feb 27 '18 at 8:46
  • $\begingroup$ @Wyck a typical display is non calibrated. $\endgroup$ – joojaa Feb 28 '18 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.