After the fun with the “doctored” photo from a previous article, I thought it would be nice to show another example of a photo that “fades to gray” if you’re not careful. This time the image disappears if it is converted to grayscale in the wrong way. This is the original image:
Below, the image is converted to grayscale. For the image on the left, both gamma correction and the perception of the human eye is taken into account. The human eye is most sensitive to green, and, for converting an image to grayscale, the recommended percentages are something like 30% for red, 59% for green, and 11% for blue. For the image on the right, the conversion to grayscale has been performed “naively”, by just averaging the three channels.
The original (green) image is most certainly not simply the green channel of a grayscale image. An image like that would never change into solid gray when you add the red, green, and blue channels, since the red and blue channels would contain nothing but zeros. The trick is starting with a uniformly gray image, then adding an image to the green channel, and then compensating for this by subtracting half of the intensity of the grayscale image from each of the red and blue channels…
Technical Details
How to correctly convert an image to grayscale? For each pixel \(p=(r,g,b)\) of the image, which is stored in its file compensated for screen gamma as \(\hat p=(\hat r,\hat g,\hat b)\), do the following:
- Undo the gamma correction that is present in the image file.
- Convert the image to grayscale using the recommended percentages.
- Apply the gamma correction again.
Or, in symbols,
\[p=\hat p^\gamma \quad\longrightarrow\quad
t=0.3r+0.59g+0.11b \quad\longrightarrow\quad
p=(t,t,t) \quad\longrightarrow\quad
\hat p=p^{1/\gamma}.
\] The standard value for \(\gamma\) is 2.2; the exponentiation must be performed on each channel separately. For some file formats, a grayscale image is not stored as three color channels with the same value, but as a single channel. In that case, just set \(\hat t=t^{1/\gamma}\) and store the gray level like that.
The naive way to convert the image to grayscale is to simply average the three color channels together, so
\[t=(\hat r+\hat g+\hat b)/3 \quad\longrightarrow\quad \hat p=(t,t,t).
\] This produces the gray image above, for the green “trick” photo.
Add new comment