Está en la página 1de 6

Color

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 Windows programs for example this can be programs, example, 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.
1 February 10, 2011 Computer Vision Lecture 4: Image Filtering 2

RGB
February 10, 2011 Computer Vision Lecture 4: Image Filtering

HSI

Conversion from RGB to HSI


Then we compute the values r, g, b that are independent of intensity: 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 rgbcube.
February 10, 2011 Computer Vision Lecture 4: Image Filtering 3

Conversion from RGB to HSI


green p-w H p = (r, g, b) pr - w red (pr) (p w = (1/3, 1/3, 1/3) (white)

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

Conversion from RGB to HSI


Then we have:

Conversion from RGB to HSI


We can also compute:

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

Since w = (1/3, 1/3, 1/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

Conversion from RGB to HSI


The saturation is the distance on the triangle in the rgbrgb-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:

Limitations of RGB and HSI


Using three individual wavelengths to represent color can never cover the entire visible range of colors:

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

February 10, 2011

Limitations of any Color Representation


Our perception of an objects color does not only depend on the frequency spectrum emitted from the objects 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. The underlying perceptual mechanisms are not fully understood yet.
February 10, 2011 Computer Vision Lecture 4: Image Filtering 9

Limitations of any Color Representation

February 10, 2011

Computer Vision Lecture 4: Image Filtering

10

Limitations of any Color Representation Lets move on to

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

implement decreasing influence by b more di t t pixels distant i l


1 4 4 16 26 16 4 7 26 41 26 7 4 16 26 16 4 1 4 7 4 1
22

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

Computer Vision Lecture 4: Image Filtering

Image Filtering
Effect of Gaussian smoothing:

Properties of Gaussian Filters


The application of Gaussian convolution filters can be made more efficient. efficient. This is important, for example, if we want to apply different Gaussian filters to a large number of big input images. The basic idea is to separate the convolution with the 2D Gaussian filter into two successive convolutions with 1D Gaussian filters. One of these filters is vertical, the other one vertical, horizontal. horizontal.
February 10, 2011 Computer Vision Lecture 4: Image Filtering 24

original
February 10, 2011

33

99

15 1515
23

Computer Vision Lecture 4: Image Filtering

Properties of Gaussian Filters


The general form of the Gaussian filter, without a normalizing factor, is given by:

Properties of Gaussian Filters


Then we have:

g[i, j ] = e

i2 + j2 2 2

g[i, j ] * f [i, j ] = g[k , l ] f [i k , j l ]


k =1 l =1

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

g[i, j ] * f [i, j ] = g[k , l ] f [i k , j l ]


k =1 l =1

= 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

Computer Vision Lecture 4: Image Filtering

Properties of Gaussian Filters


The formula in the curly braces describes the convolution of f[i, j] with a horizontal onef[i onedimensional Gaussian filter. filter. The remainder of the formula takes the result of this first convolution and performs a convolution with a vertical one-dimensional Gaussian filter on it. oneit So instead of applying an mn Gaussian convolution filter, we can successively apply a 1n filter and an 1 m1 filter. This increases the efficiency of computation.
February 10, 2011 Computer Vision Lecture 4: Image Filtering 27

Different Types of Filters


Smoothing can reduce noise in the image. This can be useful, for example, if you want to find regions of similar color or texture in an image. However, there are different types of noise. noise. For so-called salt-and-pepper noise, for example, sosalt-anda median filter can be more effective.

February 10, 2011

Computer Vision Lecture 4: Image Filtering

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.

February 10, 2011

Computer Vision Lecture 4: Image Filtering

30

Median Filter

original image
February 10, 2011

33 median
Computer Vision Lecture 4: Image Filtering

77 median
31

También podría gustarte