(Chapter Four - Color Images Formats (RGB, HSV and YCbCr

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Chapter Four

Color images formats (RGB, HSV and YCbCr)


4.1 RGB Color Model

Any color that can be represented on a computer monitor is specified by means


of the three basic colors- Red, Green and Blue called the RGB colors. By mixing
appropriate percentages of these basic colors, one can design almost any color
one ever imagines.
The model of designing colors based on the intensities of their RGB components
is called the RGB model, and it’s a fundamental concept in computer graphics.
Each color, therefore, is represented by a triplet (Red, Green, and Blue), in which
red, green and blue three bytes are that represent the basic color components.
The smallest value, 0, indicates the absence of color. The largest value, 255,
indicates full intensity or saturation. The triplet (0, 0, 0) is black, because all colors
are missing, and the triplet (255, 255, 255) is white. Other colors have various
combinations:

( 255,0,0 ) is pure red, ( 0,255,255 ) is a pure cyan ( what one gets when green and
blue are mixed ), and ( 0,128,128 ) is a mid-cyan ( a mix of mid-green and mid-
blue tones ). The possible combinations of the three basic color components are
256x256x256, or 16,777,216 colors. Figure (4.1 ) shows Color specification of the
RGB Color Cube.

The process of generating colors with three basic components is based on the
RGB Color cube as shown in the figure (4.1). The three dimensions of the color
cube correspond to the three basic colors.

1
Figure (4.1): Color specification of the RGB Color Cube

The cube's corners are assigned each of the three primary colors, their
complements, and the colors black and white. Complementary colors are easily
calculated by subtracting the Color values from 255. For example, the color
(0, 0,255) is a pure blue tone.

Its complementary color is (255-0,255-0,255-255), or (255, 255, 0), which is a


pure yellow tone see Figure (4.2). Blue and Yellow are complementary colors, and
they are mapped to opposite corners of the cube. The same is true for red and cyan,
green and magenta, and black and white.

Figure (4.2): RGB Color Model

2
 Adding a color to its complement gives white.
 It is noticed that the components of the colors at the corners of the cube have
either zero or full intensity.
 As we move from one corner to another along the same edge of the cube,
only one of its components changes value. For example, as we move from
the Green to the Yellow corner, the Red component changes from 0 to 255.
 Although we can specify more than 16 million colors, we can’t have more
than 256 shades of Gray. The reason is that a gray tone, including the two
extremes (black and white), is made up of equal values of all the three
primary colors. This is seen from the RGB cube as well. Gray shades lie on
the cube’s diagonal that goes from black to white. As we move along this
path, all three basic components change value, but they are always equal.
The value (128,128,128) is a mid-gray tone
 That's why it is wasteful to store grayscale pictures using 16-million color
True Color file formats.
 Once an image is known in grayscale, we needn’t store all three bytes
per pixel. One value is adequate (the other two components have the
same value).

4.2 HSV color Model

 HSL and HSV are two related representations of points in an RGB color space,
which attempt to describe perceptual color relationships more accurately than
RGB, while remaining computationally simple.
 HSL stands for hue, saturation, lightness, while HSV stands for hue,
saturation, value.

3
Hue: the color type (such as red, blue, or yellow). a blue car reflects blue hue.
The hue which is essentially the chromatic component of our perception may again
be considered as weak hue or strong hue.

Saturation: The colorfulness of a color is described by the saturation component.


For example, the color from a single monochromatic source of light, which
produce colors of a single wavelength only , is highly saturated , while the colors
comprising hues of different wavelengths have little Chroma and have less
saturation.

The gray colors do not have any hue and hence they have less saturation or
unsaturated. Saturation is thus a measure of colorfulness or whiteness in the color
perceived.

The lightness (L) or intensity (I) or value (V) : essentially provides a measure of
the brightness of colors. This gives a measure of how much light is reflected from
the object or how much light is emitted from a region.

The HSV model is commonly used in computer graphics applications. The HSV
color space is compatible with human color perception

The HSV image may be computed from RGB image using different
transformation. Some of them are as follows:

The simplest form of HSV transformation is :

H= tan [3(G-B)/(R-G) +(R-B)]

S= 1-(min(R, G, B)/V)

V= (R+G+B/3)

However, the hue (H) becomes undefined when saturation S=0


4
The most popular form of HSV transformation is shown next, where
the r,g,b values are first obtained by normalizing each pixel such that
r=(R/(R+G+B)), g=(G/(R+G+B)), b=(B/(R+G+B))
Accordingly the H, S and V value can be computed as:
V = max (r, g, b),

H = H+360 if H<0

4.3 YCbCr Color Format

Another color space in which luminance and chrominance are separately


represented is the YCbCr. The Y component takes values from 16 to 235, while Cb
and Cr take values from 16 to 240. They are obtained from gamma-corrected R, G,
B values as follows:

Y
Cb =
Cr

5
4.4 Basic Relationships between Pixels

In this section, several important relationships between pixels in a digital image are
considered. As mentioned before, an image is denoted by f(x, y).When referring in
this section to a particular pixel.

1. Neighbors of a Pixel
a. N4(p) : four neighbors of pixel P.
Any pixel p(x, y) has two vertical and two horizontal neighbors, given
by: (x+1,y), (x-1, y), (x, y+1), (x, y-1)
This set of pixels are called the 4-neighbors of P, and is denoted by
N4(P)
Each of them is at a unit distance from P., and some of the neighbors
of p lie outside the digital image if (x, y) is on the border of the image.

b. ND(p) : four diagonal neighbors of pixel P, denoted by ND(p).


have coordinates :(x+1, y+1), (x+1, y-1), (x-1, y+1), (x-1, y-1).
Each of them are at Euclidean distance of 1.414 from P.
c. N8(p) These points, together with the 4-neighbors, are called the 8-
neighbors of p, denoted by N8 (p).
As before, some of the points in ND(p) and N8(p) fall outside the image if
(x, y) is on the border of the image.

6
2. Adjacency
Two pixels are connected if they are neighbors and their gray levels
satisfy some specified criterion of similarity.
For example, in a binary image two pixels are connected if they are 4-
neighbors and have same value (0/1)
Let v: a set of intensity values used to define adjacency and connectivity.
In a binary Image v={1}, if we are referring to adjacency of pixels with
value 1.
In a Gray scale image, the idea is the same, but v typically contains more
elements,for example v= {180, 181, 182,....,200}.
If the possible intensity values 0 to 255, v set could be any subset of these
256 values.

7
Chapter Five
Image Compression
5.1 Introduction
In general, data compression is defined as the process of encoding data using
a representation that reduces the overall size of data. This reduction is
possible when the original dataset contains some type of redundancy.
Digital image compression is a field that studies methods for reducing the
total number of bits required to represent an image. Image compression
involves reducing the size of image data file, while is retaining necessary
information, the reduced file is called the compressed file and is used to
reconstruct the image, resulting in the decompressed image. The original image,
before any compression is performed, is called the uncompressed image file. The
ratio of the original, uncompressed image file and the compressed file is referred to
as the compression ratio.

1. Compression Ratio = Uncompressed File¿ ¿ Cmpressed File ¿¿ ¿¿¿¿¿ ¿ ¿ ¿


It is often written as Size u: Size C

Compression techniques are used to reduce the redundant


information in the image data in order to facilitate the storage,
transmission and distribution of images (e.g. GIF, TIFF, PNG,
JPEG).
Example: An original image Image 256X256 pixels, 256 level gray scale can be
compressed with file size 6554 byte. Find the compression ratio.

Original Image Size = 256X256 (pixels) * 1 (byte/pixel)

= 65536 bytes

8
65536
Compression ratio = 6554
≈ 10

this can be written as: 10:1

2. Number of Bits
Bits per Pixel 
Number of Pixels

Example: An original image 256X256 pixels, 256 level gray scale can
be compressed file size 6554 byte.
Original Image Size = 256X256 (pixels) * 1 (byte/pixel)
= 65536 bytes
Compressed file = 6554 (bytes) * 8 (bits/pixel)
= 52432 bits
52432
Bit per Pixel = 65536
=¿ 0.8 bit / pixel

Q: Why we want to compress?


To transmit a digitized color scanned at 3,000×2,000 pixels, and 24 bits,
at 28.8(kilobits/second), it would take about:
3000∗2000 ( pixels )∗24(bits/ pixels)
=4883 Second=81 minutes
28.8∗1024( bits/ second)

Q: What is the key of compression??

9
 Reducing Data but Retaining Information,
 DATA are used to convey information
For digital images, data refer to pixel gray-level values which
correspond to the brightness of a pixel at a point in space. Information
is interpretation of the data in a meaningful way. Data are used to
convey information, much like the way the alphabet is used to convey
information via words. Information is an elusive concept, it can be
application specific. For example, in a binary image that contains text
only, the necessary information may only involve the text being
readable, whereas for a medical image the necessary information may
be every minute detail in the original image.

5.2 Compression System Model


The compression system model consists of two parts: Compressor and
Decompressor.

Compressor: consists of preprocessing stage and encoding stage.

Decompressor: consists of decoding stage followed by a post


processing stage
Figure 5.3 depicts a general data compression scheme, in which
compression is performed by an encoder and decompression is
performed by a decoder.
We call the output of the encoder codes or codewords. The intermediate
medium could either be data storage or a communication/computer
network. If the compression and decompression processes induce no
10
information loss, the compression scheme is lossless; otherwise, it is
lossy.

Figure (5.1): Compression System Model

5.3 Lossy Compression


These compression methods are called Lossy because they allow a loss
because they allow a loss in actual image data, so original uncompressed
image can not be created exactly from the compressed file. For complex
images these techniques can achieve compression ratios of 100 0r 200
and still retain in high – quality visual information. For simple image or
lower-quality results compression ratios as high as 100 to 200 can be
attained. Lossy compression yields a much higher compression ratio
than that of loss-less compression. Table (5.1) shows differences
between lossy and lossless compression

Table (5.1) : the comparison between Lossy and Lossless compression

Lossless Compression Lossy Compression

11
1. All original data can be recovered 1. Reduces a file by permanently
when the file is uncompressed every eliminating certain information,
single bit of data that was originally especially redundant information
in the file remains after the file is
uncompressed. 2. When the file is uncompressed, only
a part of the original information is
2. All of the information is completely still there (although the user may not
restored notice it)

3. This is generally the technique of 3. Lossy compression is generally used


choice for text or spreadsheet files, for video and sound where a certain
where losing words or financial data amount of information loss will not
could pose a problem be detected by most users

4. The Graphics Interchange File (GIF) 4. The JPEG image file, commonly
is an image format used on the Web used for photographs and other
that provides lossless compression. complex still images on the Web, is
an image that has lossy
compression.

5.4 Lossless Compression

Lossless compression methods are necessary in some imaging applications. All of


the information is completely restored ( no data are lost). This is generally the
technique of choice for text or spreadsheet files, where losing words or financial
data could pose a problem. In addition, with medical image, the law requires that
any archived medical images are stored without any data loss. Lossless
compressors (Figure 5.2) are usually two step algorithms. The first step
transforms the original image to some other format in which the inter -pixel
redundancy is reduced. The second step uses an entropy encoder to remove the

12
coding redundancy. The lossless decompressor is a perfect inverse process of the
lossless compressor.

Typically, medical images can be compressed losslessly to about 50%


of their original size

An important concepts here is the ides of measuring the average information in an


image, referred to as entropy. The entropy for N×N image can be calculated by
equation 5.3.

----- -------- (5.3)

Where:
nk
Pi = The probability of the ith gray level
N2
n k = the total number of pixels with gray value k.
L = the total number of gray levels (e.g. 256 for 8-bits)

Not : The compression ratio for image data using lossless


compression techniques is low when the image histogram is
relatively flat.
Example :
Example
Let L=8, meaning that there are 3 bits/ pixel in the original image. Let that
number of pixel at each gray level value is equal (they have the same
probability) that is:
8
1
0 1 2 7 P1 P2 P3 P7 
Now, we can calculate the entropy as follows:
Now, we can calculate the entropy as follows:

13
Entropy=-Plog(P

1/8log (1/8)=3

5.6 Distortion Measures


In order to evaluate the performance of the image compression coding, it is
necessary to define a measurement that can estimate the difference between the
original image and the decoded image. Two common used measure ements are the
Mean Square Error (MSE) and the Peak Signal to Noise Ratio (PSNR) , which
are defined in (5.1) and (5.2), respectively, where xn is the pixel value of the
original image, and yn the pixel value of the decoded image and N is the length of
original image. Most image compression systems are designed to minimize the
MSE and maximize the PSNR.

N
Mean Square Error (MSE) σ2,  2  1
N  (x
n 1
n  yn ) 2 ----- -------- (5.1)

------ -------- (5.2)

14

You might also like