Document

advertisement
Color
HSI
RGB
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
1
Conversion from RGB to HSI
It is not too difficult to convert RGB values into HSI
values to facilitate color processing in computer vision
applications.
First of all, we normalize the range of the R, G, and
B components to the interval from 0 to 1.
For example, for 24-bit color information, this can be
done by dividing each value by 255.
Then we compute the intensity I as
I = 1/3*(R + G + B).
Obviously, intensity also ranges from 0 to 1.
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
2
Conversion from RGB to HSI
Then we compute the values r, g, b that are
independent of intensity:
r = R/(R + G + B)
g = G/(R + G + B)
b = B/(R + G + B)
When we consider the RGB cube, then all possible
triples (r, g, b) lie on a triangle with corners (1, 0, 0),
(0, 1, 0), and (0, 0, 1).
We could call this the rgb-subspace of our RGB
cube.
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
3
Conversion from RGB to HSI
green
p-w
p = (r, g, b)
H
blue
pr - w
red (pr)
w = (1/3, 1/3, 1/3) (white)
The hue is the angle H from vector pr – w to vector p – w.
The saturation is the distance from w to p relative to the
distance from w to the fully saturated color of the same hue as
p (on the edge of the triangle).
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
4
Conversion from RGB to HSI
Then we have:
(p  w )  (p r  w )
cos H 
|| p  w ||  || p r  w ||
Since w = (1/3, 1/3, 1/3):
|| p  w || (r  1 / 3)  ( g  1 / 3)  (b  1 / 3)
2
2
2
And since pr = (1, 0, 0):
|| p r  w || 2 / 3
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
5
Conversion from RGB to HSI
We can also compute:
2(r  1 / 3)  ( g  1 / 3)  (b  1 / 3)
(p  w )  (p r  w ) 
3
With the above formulas, including those for deriving
r, g, and b from R, G, and B, we can determine an
equation for computing H directly from R, G, and B:
cos H 
2R  G  B
2 ( R  G )  ( R  B)(G  B)
September 17, 2013
2
Computer Vision
Lecture 5: Image Filtering
6
Conversion from RGB to HSI
Note that when we use the arccos function to
compute H, arccos always gives you a value between
0 and 180 degrees.
However, H can assume values between 0 and 360
degrees.
If B > G, then H must be greater than 180 degrees.
Therefore, if B > G, just compute H as before and
then take (360 degrees – H) as the actual hue value.
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
7
Conversion from RGB to HSI
The saturation is the distance on the triangle in the
rgb-subspace from white relative to the distance from
white to the fully saturated color with the same hue.
Fully saturated colors are on the edges of the
triangle.
The derivation of the formula for saturation S is very
lengthy, so we will just take a look at the result:
3
S  1
min( R, G, B)
RG B
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
8
Limitations of RGB and HSI
Using three individual wavelengths to represent color
can never cover the entire visible range of colors:
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
9
Limitations of any Color Representation
It is important to note (again) that our perception of an
object’s color does not only depend on the frequency
spectrum emitted from the object’s location.
It also depends on the spectra of other objects or
regions in the visual field.
This mechanism called color constancy allows us to
assign a color to a given object that is invariant to
shading or illumination of the scene by varying light
sources.
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
10
Limitations of any Color Representation
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
11
Limitations of any Color Representation
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
12
Let’s move on to…
Image Filtering
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
13
Histogram Modification
A common and important filter operation is
histogram modification.
Between any two stages of image processing, it often
happens that the range of intensity values in our
image is only a small proportion of the possible
range.
This means that the contrast in the image is weaker
than it would have to be.
It is then useful to modify the intensity histogram of
the image.
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
14
Histogram Modification
One possible method for this is image scaling: We
simply expand the range [a, b] containing most of the
intensities in the image to fill the entire range [z1, zk].
This means that the value z of each pixel in the
original image is mapped onto the value z’ in the
scaled image in the following way:
zk  z1
z' 
( z  a)  z1
ba
Notice that this method may leave gaps between bins
in the resulting histogram.
September 17, 2013
Computer Vision
Lecture 5: Image Filtering
15
Download