|
Source: (largely custom); [SEUL00:51-55], [FOLE90:589-592]
It’s debatable whether or not something as simple as a color conversion to grayscale is actually a ‘filter’ or not. Photoshop® does not include it in its list of filters, but then I do not think that any of Photoshop’s® filters are point processes. At any rate, it does conform to the definition given here and it is a simple place to begin. It also brings to the foreground one of the most important issues about color processing which we will use in subsequent filters.
That issue about color deals with how to simply categorize color. That is, how to convert the three RGB values of a pixel into a single value. Many of the filter algorithms I looked at were for black and white images. This is easy to represent on a computer. Each pixel is a byte which can have 256 different values (i.e. [0..255]), or 256 levels of gray. When an algorithm (as we will see later) calls for ‘the most frequent color’ and there are only 256 different possibilities, this is easy, but with a color image, there are 2563 = 16,777,216 different possibilities! It’s possible that every pixel in an image could be a ‘different’ color!
As it turns out, the answer has to do with color intensity, or luminance. As [FOLE90:602] states: “the eye is more sensitive to spatial variation in intensity than it is to variation in chromaticity.” Therefore, if we can convert our RGB pixel into a single value, based on intensity, it will be a good way to describe the properties of that pixel using a smaller range than 16.7 million [SEUL00:51-55].
Actually, this concept is used in television display. The National Television Standards Committee uses a YIQ color model to broadcast television signals (in contrast to the RGB and HSV color models described earlier). The Y encodes the color luminance (intensity), while I and Q encode chromaticity. The Y component is all that is used to display an image on a black and white television, and in fact, because intensity (luminance) is the most distinguishing factor in color, more bandwidth is used to represent Y than I or Q, even for color displays [FOLE90:589-590].
There are a few different formulas to evaluate intensity from an RGB pixel. The RGB to HSV conversion described in [FOLY90:592] simply uses the maximum value of each of the RGB components (e.g. color (180, 200, 90) would have intensity 200). Another model takes the average of the three components. Surprisingly, both of these methods produce satisfactory results. However, the intensity calculation from the YIQ model uses a weighted average of each pixel component, with green having the most weight, red about half as much as green, and blue about half as much as red. This idea is agreeable with color theory. That is, green is more intense than red, which is more intense than blue. Below is the FilterExplorer pixel member function for intensity:
BYTE pixel::intensity()
{
return BYTE(0.3*r + 0.59*g + 0.11*b);
}
After that lengthy discussion, the implementation of a grayscale conversion, based on intensity is easy. Here is the
pseudocode:
for every pixel in the image do
{
intensity = currentpixel.intensity();
filterpixel.r = intensity;
filterpixel.g = intensity;
filterpixel.b = intensity;
}
The reader should note that for an RGB pixel to be gray, all components have to be the same value.
FilterExplorer has two additional grayscale conversions. One based on hue, the other on saturation. Hue is a circular measure based on degrees. In this model, 0 degrees is red, 120 degrees is green, and 240 degrees is blue. Therefore, converted to grayscale, a pixel value of 0 (black) corresponds to pure red, 85 (dark gray) will represent pure green, and 170 (light gray) will represent pure blue. (Note also that a pixel value of 1 (white) will also represent pure red.) These two filters use the HSV color model:
// grayscale by hue
for every pixel in the image do
{
hsvpixel = currentRGBpixel;
filterpixel.r = hsvpixel.h;
filterpixel.g = hsvpixel.h;
filterpixel.b = hsvpixel.h;
}
// grayscale by saturation
for every pixel in the image do
{
hsvpixel = currentRGBpixel;
filterpixel.r = hsvpixel.s;
filterpixel.g = hsvpixel.s;
filterpixel.b = hsvpixel.s;
}
Each of these filters simply use the hue or saturation component of the RGB pixel converted to HSV in assigning the filter pixel value. The formula of the RGB to HSV conversion is beyond the scope of this report. The interested reader should see [FOLE90:592-593], [PCIIHS], or
[PCIRGB].

Grayscale by Intensity

Grayscale by Hue

Grayscale by Saturation
Return to the list of filters
|