Beruflich Dokumente
Kultur Dokumente
COLOR
Representation of color in MATLAB
It is represented through a MxNx3 matrix, where M is the width of the image, N is the height and there are
three matrices, one for each color component in the space in which it is represented. Usually, this color space
is RGB (Red, Green, Blue).
For each pixel of the image, instead of having a numeric value representing the level of grey, we have a
vector that represents the color. Each component of the vector represents the intensity of the color in the
corresponding channel.
In MATLAB, you can not only use RGB, but many other color spaces like CMY, CMYK, HSV, HSI, NTSC
Color Space, etc. Here we'll work exclusively with RGB and CMY.
Color maps
Another way of representing an image in MATLAB is through a color map, where we have an image
represented by a matrix X (MxN) and a matrix C of dimensions Kx3, that represents the color space, where
K is the number of colors in that space.
Each component of matrix X is an integer between 1 and K. To know the color of that pixel, we just select
the corresponding row in C, the three values of that row will represent the color of the corresponding pixel.
http://imgprocessing.tk/improve/color.html 1/4
12/31/2016 Color
Representation conversion
To change the representation of an image from RGB to Colormap, we can use the following command:
[X, map] = rgb2ind(f, num_of_colors, option)
To represent the result, we use the following command:
figure, imshow(X, map)
Intensity transformations
To perform an intensity transformation in all the color components or in independent components (red, blue,
green, cyan, magenta...) we'll use the following MATLAB command:
g = ice('image', f)
The command shows the following window through the UI:
http://imgprocessing.tk/improve/color.html 2/4
12/31/2016 Color
Color filtering
The filtering of color images is done in the same way than with images in gray scale, with imfilter() , but
instead of passing it a gray scale image, we pass it a color image.
Each of the color images are filtered separately and then they are joined back again in a single image with
three color components.
Colored borders detection
The border detection is not transformable any more as the filtering, we can not detect the borders in each
color component and then join the images because it wouldn't work.
We are now faced with the following problem (where r, g and u are unit vectors):
u→=∂R∂xr→+∂G∂xg→+∂B∂xb→
v→=∂R∂yr→+∂G∂yg→+∂B∂yb→
gxx=u→·u→=u→T·u→=∂R∂x2+∂G∂x2+∂B∂x2
http://imgprocessing.tk/improve/color.html 3/4
12/31/2016 Color
gyy=v→·v→=v→T·v→=∂R∂y2+∂G∂y2+∂B∂y2
gxy=u→·v→=u→T·v→=∂R∂x∂R∂y+∂G∂x∂G∂y+∂B∂x∂B∂y
θ(x,y)=12tan12gxygxxgyy
Fθ(x,y)=12gxx+gyy+gxxgyycos2θ+2gxysin2θ12
F represents the gradient in the θ direction, where the gradient has a maximum.
To calculate the value of F we use the following command:
[VG, A, PPG] = colorgrad(f)
You can practice these concepts using snippet10 .
http://imgprocessing.tk/improve/color.html 4/4