Convert RGB To HSI
Convert RGB To HSI
RGB
February 10, 2011 Computer Vision Lecture 4: Image Filtering
HSI
blue
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).
February 10, 2011 Computer Vision Lecture 4: Image Filtering 4
cos H =
(p w ) (p r w ) || p w || || p r w ||
(p w ) (p r w ) =
2(r 1 / 3) ( g 1 / 3) (b 1 / 3) 3
|| p w ||= (r 1 / 3) 2 + ( g 1 / 3) 2 + (b 1 / 3) 2
And since pr = (1, 0, 0):
With the above formulas, including those for deriving r, g, and b f d from R G and B we can d t R, G, d B, determine an i equation for computing H directly from R, G, and B:
cos H =
2R G B 2 ( R G ) 2 + ( R B)(G B )
Computer Vision Lecture 4: Image Filtering 6
|| p r w ||= 2 / 3
February 10, 2011 Computer Vision Lecture 4: Image Filtering 5 February 10, 2011
S = 1
3 min( R, G , B ) R+G + B
Computer Vision Lecture 4: Image Filtering 7 February 10, 2011 Computer Vision Lecture 4: Image Filtering 8
10
Image Filtering
February 10, 2011 Computer Vision Lecture 4: Image Filtering 11 February 10, 2011 Computer Vision Lecture 4: Image Filtering 12
Histogram Modification
A common and important filter operation is histogram modification. 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. 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.
February 10, 2011 Computer Vision Lecture 4: Image Filtering 13
Histogram Modification
One possible method for this is image scaling: We scaling: 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:
z' =
z k z1 ( z a ) + z1 ba
Notice that this method may leave gaps between bins in the resulting histogram.
February 10, 2011 Computer Vision Lecture 4: Image Filtering 14
Image Filtering
Many basic image processing techniques are based on convolution. In a convolution, a convolution filter W pp y pixel of an image I to create a g is applied to every p filtered image I*:
I * ( x, y ) = I ( x, y ) * W ( x, y ) =
u = v =
Image Filtering
Example: Averaging filter: y
0 0 0 0 0 0 0 0 1/9 1/9 1/9 0 0 0 0 0 0 1/9 1/9 1/9 1/9 1/9 1/9 0 0
I (u, v)W (u x, v y)
I * ( x, y ) = I ( x, y ) * W ( x, y ) =
February 10, 2011 Computer Vision Lecture 4: Image Filtering 15 February 10, 2011
u = v =
Computer Vision Lecture 4: Image Filtering
I (u, v)W (u x, v y)
16
Image Filtering
Image:
1 2 5 3 4 6 11 10 1 4 3 3 6 0 2 2 10 9 2 9 9 0 7 8 10 New value: 6/9 + 9/9 + 7/9 + 0/9 + 2/9 + 8/9 + 2/9 + 9/9 + 10/9 = 5.889
Image Filtering
Grayscale Image: Averaging Filter:
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9
Filter:
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1 2 5 3 4 6 11 10 1 4 3 3 6 0 2 2 10 9 2 9 9 0 7 8 10
I * ( x, y ) = I ( x, y ) * W ( x, y ) =
February 10, 2011
u = v =
Computer Vision Lecture 4: Image Filtering
I (u, v)W (u x, v y)
17 February 10, 2011 Computer Vision Lecture 4: Image Filtering 18
Image Filtering
Original Image:
1 1/9 6 1/9 3 1/9 2 2 1/9 11 1/9 3 1/9 10 5 1/9 10 1/9 6 1/9 9 3 4 1 4 0 2 2 9 9 0 7 8 10
Image Filtering
Original Image:
0 0 0 0 1 2 5 3 4 6 3 2 9 1/9 1/9 1/9 11 3 10 0 1/9 1/9 1/9 10 6 9 7 1/9 1/9 1/9 1 4 0 2 2 9 8 10
Filtered Image:
0 0 0 0 0 0 0 0 0 5 0 0
Filtered Image:
0 0 0 0 0 0 0 0 0 5 0 7 0 0 0 0 0 0
value = 11/9 + 61/9 + 31/9 + 21/9 + 111/9 + 31/9 + 51/9 + 101/9 + 61/9 = 47/9 = 5.222
February 10, 2011 Computer Vision Lecture 4: Image Filtering 19
value = 61/9 + 31/9 + 21/9 + 111/9 + 31/9 + 101/9 + 101/9 + 61/9 + 91/9 = 60/9 = 6.667
February 10, 2011 Computer Vision Lecture 4: Image Filtering 20
Image Filtering
Original Image:
1 2 5 3 4 6 11 10 1 4 3 3 6 0 2 2 10 9 2 9 9 0 7 8 10
Image Filtering
More common: Gaussian Filters
0 0 0 0 0
x2 + y2 2 2
Filtered Image:
0 0 0 0 0 0 5 5 4 0 0 7 6 5 0 0 5 5 6 0
W ( x, y ) = G ( x, y ) =
1 2
2
Discrete version: Now you can see the averaging (smoothing) effect of the 33 filter that we applied.
February 10, 2011 Computer Vision Lecture 4: Image Filtering 21 February 10, 2011
1/273
7 4 1
Image Filtering
Effect of Gaussian smoothing:
original
February 10, 2011
33
99
15 1515
23
g[i, j ] = e
i2 + j2 2 2
The convolution of an image f[i, j] with a Gaussian filter of size mn is given by: m
= e
k =1 l =1
n
k 2 +l 2 2 2
f [i k , j l ]
l2
= e
k2 2 2
2 2
2
f [i k , j l ]
This formula needs to be applied to all coordinates [i, j] in f in order to create the convoluted image.
February 10, 2011 Computer Vision Lecture 4: Image Filtering 25 February 10, 2011
= e
k =1
k =1 l =1 k2 m 2 2
n l2 e 2 f [i k , j l ] l =1
26
28
Median Filter
Use, for example, a 33 filter and move it across 3 the image like we did before. For each position, compute the median of the brightness values of the nine pixels in question. To compute the median, sort the nine values in ascending order order. The value in the center of the list (here, the fifth value) is the median. Use the median as the new value for the center pixel.
February 10, 2011 Computer Vision Lecture 4: Image Filtering 29
Median Filter
Advantage of the median filter: Capable of eliminating outliers such as the extreme brightness values in salt-and-pepper noise. salt-and Disadvantage: The median filter may change the contours of objects in the image.
30
Median Filter
original image
February 10, 2011
33 median
Computer Vision Lecture 4: Image Filtering
77 median
31