Chapter 2 - Basic Techniques in Image Processing

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 90

TRƯỜNG ĐẠI HỌC CÔNG NGHIỆP TP HỒ CHÍ MINH

Dr. Tran Minh Chinh


References

“Digital Image Processing”, Fourth Edition,


Rafael C. Gonzalez & Richard E. Woods.

Richard Szeliski. Computer Vision:


Algorithms and Applications. Springer, 2011.

Forsyth D. Computer Vision: A Modern


Approach. Prentice Hall. 2011.

2
COURSE CONTENT

3
Chapter 2:

BASIC TECHNIQUES IN
IMAGE PROCESSING
5
Chapter 2

2.1 FUNDAMENTAL OF
DIGITAL IMAGE

6
2.1.1 ELEMENTS OF VISUAL PERCEPTION
STRUCTURE OF THE HUMAN EYE

7
1.The lens contains 60-70% water, 6% of fat.
2.The iris diaphragm controls amount of light that enters the
eye.
3.Light receptors in the retina
- About 6-7 millions cones for bright light vision called
photopic
- Density of cones is about 150,000 elements/mm2.
- Cones involve in color vision.
- Cones are concentrated in fovea about 1.5x1.5 mm2.
- About 75-150 millions rods for dim light vision called
scotopic
- Rods are sensitive to low level of light and are not involved
color vision.
4. Blind spot is the region of emergence of the optic nerve
from the eye. 8
IMAGE FORMATION IN THE EYE

 Muscles within the eye can be used to change the shape of


the lens allowing us focus on objects that are near or far
away.
 An image is focused onto the retina causing rods and cones
to become excited which ultimately send signals to the
brain.
9
LIGHT AND THE ELECTROMAGNETIC SPECTRUM

The electromagnetic spectrum. 10


2.1.2 IMAGE REPRESENTATION

Digital image = a multidimensional


array of numbers (such as intensity image)
or vectors (such as color image)

Each component in the 10 10 16 28


 9 656 70 56  43
image called pixel associates  32 99
26
54 70
37  78
 67 
96 56
with the pixel value (a single 15  256013 902296
  67
  21  54 47  42 
number in the case of 32  158587 853943  92
54  65 65 39 
intensity images or a vector 32 65 87 99
in the case of color images). 11
Digital Image Types : Intensity Image
Intensity image or monochrome image
each pixel corresponds to light
intensity normally represented in
gray scale (gray level).

Gray scale values


10 10 16 28
 9 6 26 37
 
15 25 13 22
 
32 15 87 39
12
Digital Image Types : RGB Image
Color image or RGB image:
each pixel contains a vector
representing red, green and
blue components.

RGB components
10 10 16 28
 9 656 7026
56  43
3756  78
 32 99 54 96  67 
70

15 256013 902296  67
  21  54 47  42 
32  158587 853943  92
54  65 65 39  13
32 65 87 99
Image Types : Binary Image
Binary image or black and white image
Each pixel contains one bit :
1 represent white
0 represents black

Binary data
0 0 0 0
0 0 0 0
 
1 1 1 1

1

1 1 1 14
Image Types : Index Image
Index image
Each pixel contains index number
pointing to a color in a color table

Color Table

Index Red Green Blue


No. component component component

1 0.1 0.5 0.3


2 1.0 0.0 0.0
1 4 9
6 4 7  3 0.0 1.0 0.0
 
6 5 2 4 0.5 0.5 0.5
5 0.2 0.8 0.9
Index value … … … …
15
x

Origin

y
f(x,y)

w An image: a multidimensional function of spatial coordinates.


w Spatial coordinate: (x,y) for 2D case such as photograph,
(x,y,z) for 3D case such as CT scan images
(x,y,t) for movies
w The function f may represent intensity (for monochrome images)
or color (for color images) or other associated values.

16
MxN numerical matrix form

 f (0, 0) f (0,1) ... f (0, N  1) 


 f (1, 0) f (1,1) ... f (1, N  1) 
f ( x, y )  
 ... ... ... ... 
 
 f ( M  1, 0) f ( M  1,1) ... f ( M  1, N  1) 
 a0,0 a0,1 ... a0, N 1 
 
 a1,0 a1,1 ... a1, N 1 
A
Traditional matrix form . . . 
 
 aM 1,0 aM 1,1 ... aM 1,17
N 1 

2.1.3 Basic Relationship of Pixels
(0,0) x

(x-1,y-1) (x,y-1) (x+1,y-1)

(x-1,y) (x,y) (x+1,y)


y

(x-1,y+1) (x,y+1) (x+1,y+1)

Conventional indexing method


18
Neighbors of a Pixel
Neighborhood relation is used to tell adjacent pixels. It is useful for
analyzing regions.

(x,y-1) 4-neighbors of p:

(x-1,y)
(x-1,y) p (x+1,y) (x+1,y)
N4(p) = (x,y-1)
(x,y+1)
(x,y+1)

4-neighborhood relation considers only vertical and horizontal neighbors.

Note: q N4(p) implies p N4(q) 19


Neighbors of a Pixel (cont.)

(x-1,y-1) (x,y-1) (x+1,y-1) 8-neighbors of p:

(x1,y1)
(x-1,y) p (x+1,y)
(x,y1)
(x+1,y1)
(x1,y)
(x-1,y+1) (x,y+1) (x+1,y+1) (x+1,y)
N8(p) = (x1,y+1)
(x,y+1)
(x+1,y+1)

8-neighborhood relation considers all neighbor pixels.


20
Neighbors of a Pixel (cont.)

(x-1,y-1) (x+1,y-1) Diagonal neighbors of p:

(x1,y1)
p
(x+1,y1)
ND(p) = (x1,y+1)
(x+1,y+1)
(x-1,y+1) (x+1,y+1)

Diagonal -neighborhood relation considers only diagonal neighbor pixels.

21
Distance

 For pixels p, q and z, with coordinates (x, y), (s, t)


and (v, w), respectively, D is a distance function if:
(a) D (p, q) ≥ 0 (D (p, q) = 0 if p = q),
(b) D (p, q) = D (q, p), and
(c) D (p, z) ≤ D (p, q) + D (q, z).

22
Distance Measures
 The Euclidean Distance between p and q is
defined as:
De (p, q) = [(x – s)2 + (y - t)2]1/2

23
Distance Measures
D4-distance (city-block distance) is defined as

D4 ( p, q)  x  s + y  t

2 q (s,t)

2 1 2

2 1 0 1 2

2 1 2 D4
2 p (x,y)

Pixels with D4(p) = 1 is 4-neighbors of p.


24
D8-distance (chessboard distance) is defined as

D8 ( p, q)  max( x  s , y  t )
q (s,t)
2 2 2 2 2

2 1 1 1 2
D8(b)
2 1 0 1 2

2 1 1 1 2 p (x,y) D8(a)
2 2 2 2 2
D8 = max(D8(a) , D8(b))

Pixels with D8(p) = 1 is 8-neighbors of p.

25
2.1.4 IMAGE SAMPLING AND QUANTIZATION
 The output of most sensors is a continuous voltage
waveform whose amplitude and spatial behavior are
related to the physical phenomenon being sensed.
To create a digital image, we need to convert the
continuous sensed data into a digital format. This
requires two processes: sampling and quantization.
 An image may be continuous with respect to the x- and
y-coordinates, and in amplitude.
 To digitize it, we have to sample the function in both

26
coordinates and also in amplitude.
 Digitizing the coordinate values is called sampling.
Digitizing the amplitude values is called quantization.
27
How to choose the spatial resolution
Spatial resolution = Sampling locations
Original image
Sampled image

28
Image Quantization
Image quantization:
discretize continuous pixel values into discrete numbers

Color resolution/ color depth/ levels:


- No. of colors or gray levels or
- No. of bits representing each pixel value
- No. of colors or gray levels Nc is given by

Nc  2 b

where b = no. of bits

29
A B A B

Continuous image projected Result of image sampling


onto a sensor array and quantization.

30
IMAGE SAMPLING

Image Formation

projection
through lens
image of object

31
Image Formation

projection onto
discrete sensor
digital camera
array.

32
Image Formation

continuous
colors, discrete
locations.
discrete real-
valued image

33
QUANTIZATION

discrete color output

continuous colors
mapped to a finite,
discrete set of colors.

continuous color input

34
Sampling and Quantization

real image sampled quantized sampled &


quantized

35
Effect of Spatial Resolution

256x256 pixels 128x128 pixels

64x64 pixels 32x32 pixels 36


Effect of Quantization Levels

256 levels 128 levels

37
64 levels 32 levels
Effect of Quantization Levels (cont.)

16 levels 8 levels

In this image,
it is easy to see
false contour.

4 levels 2 levels 38
Chapter 2

2.2 COLOR FUNDAMENTALS

39
2.2.1 COLOR FUNDAMENTALS

 Two factor of using color in image processing


 In automated image analysis, color is a powerful descriptor
(simplify object identification and extraction)
 The human eye can discern thousands of color shades and
intensities, compared to about two-dozen shades of gray

 Color image processing is divided into two major areas:


 Full color (TV camera or color scanner)
 Pseudo-color (particle monochrome intensity or range of
intensities)

40
2.2.1 COLOR FUNDAMENTALS

In 1666, Sir Isaac Newton discovered continuous spectrum of colors


ranging from violet at one end to red at the other.

Color spectrum seen by passing white light through a prism.

Wavelengths comprising the visible range of the electromagnetic spectrum. 41


2.2.1 COLOR FUNDAMENTALS

 The colors that human beings perceive in an object are determined


by the nature of the light reflected from the object.
 Color can only exist when three components are present:
a viewer, an object, and light.

42
2.2.1 COLOR FUNDAMENTALS

 Characterization of light is central to the science of color.

 Achromatic light
 Its only attribute is its intensity, or amount.
 Viewers see on a black and white.
 The term gray level refers to a scalar measure of intensity that
rages from black, to grays, and finally to white

Achromatic Color Schemes 43


2.2.1 COLOR FUNDAMENTALS

 Spans the electromagnetic spectrum from approximately 400


to 700 nm.

44
2.2.1 COLOR FUNDAMENTALS

Three basic quantities used to describe the quality of a


chromatic light source are: radiance, luminance, and
brightness.
 Radiance [Watt (W)]
 The total amount of energy that flows from the light source
 Luminance [Lumens (lm)]
 A measure of the amount of energy an observer perceives
from a light source
 Brightness
 A subjective descriptor that is impossible to measure
 The achromatic notion of intensity
 One of the key factors in describing color sensation

45
2.2.1 COLOR FUNDAMENTALS

Absorption of light by the red, green, and blue cones in the


human eye as a function of wavelength.
46
2.2.1 COLOR FUNDAMENTALS

 Primary colors of light : red, green, blue


The CIE specific wavelength values to the three primary
colors
 Blue= 435.8 nm, green= 546.1 nm, red= 700 nm

No mean that these three fixed RGB components acting


alone can generate all spectrum colors

 Secondary colors of light : cyan, magenta, yellow


Magenta: R+B, cyan: G+B, yellow: R+G
Mixing the three primaries, or a secondary with its opposite
primary color, in the right intensities produces white light.

47
2.2.1 COLOR FUNDAMENTALS

 Primary colors of pigments or colorants


 cyan, magenta, yellow
 A primary color of pigments is defined as one that subtracts
or absorbs a primary color of light and reflects or transmits
the other two

 Secondary colors of pigments or colorants


 red, green, blue
 Combination of the three pigment primaries, or a secondary
with its opposite primary, produces black

48
2.2.1 COLOR FUNDAMENTALS

Primary and secondary colors of


light and pigments.

49
2.2.1 COLOR FUNDAMENTALS

 Characteristics of colors
 Brightness
 The chromatic notion of intensity
 Hue
 An attribute associated with the dominant wavelength in a
mixture of light waves
 Representing dominant color as perceived by an observer
 Saturation
 Referring to relative purity or the amount of white mixed with a
hue
 Saturation is inversely proportional to the amount of white light

50
2.2.1 COLOR FUNDAMENTALS

 Hue and saturation taken together are called


chromaticity
A color may be characterized by its brightness and
chromaticity
The amounts of red, green, and blue needed to form any particular
color are called the tristimulus values
Denoted X(red), Y(green), and Z(blue)
X Y Z
x , y , z
X +Y + Z X +Y + Z X +Y + Z
x z
x + y + z 1 , X  Y ,Z  Y
y y

51
2.2.1 COLOR FUNDAMENTALS

The CIE chromaticity diagram 52


2.2.1 COLOR FUNDAMENTALS

 Chromaticity diagram
 Showing color composition as a function of x(R) and y(G)
 For any value of x and y, z(B) = 1 – (x + y)
 The positions of the various spectrum colors are indicated
around the boundary of the tongue-shaped
 The point of equal energy = equal fractions of the three
primary colors = CIE standard for white light
 Boundary : completely saturated
 Useful for color mixing
 A triangle(RGB) does not enclose the entire color region

53
2.2.2 COLOR MODELS

2.2.2 COLOR MODELS (COLOR SPACE, COLOR SYSTEM


 The purpose of a color model
To facilitate the specification of colors in some standard

 Color models are oriented either toward hardware or


applications
Hardware-oriented
 Color monitor or Video camera : RGB
 Color printer : CMY
 Color TV broadcast : YIQ ( I : inphase, q : quadrature)
Color image manipulation : HSI, HSV
Image processing : RGB, YIQ, HSI

54
2.2.2 COLOR MODELS

1 THE RGB COLOR MODELS

 RGB model is based on a


Cartesian coordinate system
The color subspace of interest is
the cube
RGB values are at three corners
Colors are defined by vectors
extending from the origin
For convenience, all color values
have been normalized Schematic of the RGB color
cube. Points along the main
 All values of R, G, and B are in
diagonal have gray values,
the range [0, 1]
from black at the origin to
white at point (1, 1, 1).

55
2.2.2 COLOR MODELS

1 THE RGB COLOR MODELS


 Images represented in the RGB color model
Images represented in the RGB color model
consist of three independent image planes, one
for each primary color
 Pixel depth
The number of bits used to represent each
pixel in RGB space is called the pixel depth
The term full-color image is used often to
denote 24-bit RGB color image

56
2.2.2 COLOR MODELS

1 THE RGB COLOR MODELS

A 24-bit RGB color cube

57
2.2.2 COLOR MODELS

1 THE RGB COLOR MODELS

Generating the RGB image of


the cross-sectional color plane The three hidden surface
(127, G, B) planes in the color cube
58
2.2.2 COLOR MODELS

2 THE CMY AND CMYK COLOR MODELS


 General purpose of CMY color model
To generate hardcopy output
 The primary colors of pigments
Cyan, magenta, and yellow
C = W - R, M = W - G, and Y = W - B

 Most devices that deposit colored pigments on paper


require CMY data input
Converting RGB to CMY  C  1  R 
 M   1  G 
    
 Y  1  B 
The inverse operation from CMY to RGB is generally of no
practical interest
59
2.2.2 COLOR MODELS

2 THE HSI COLOR MODELS

 Usefulness
 The intensity is decoupled from the color information

 The hue and saturation are intimately related to the way in


which human beings perceive color

 An ideal tool for developing image procession algorithms


based on some of the color sensing properties of the human
visual system

60
2.2.2 COLOR MODELS

2 THE HSI COLOR MODELS

 HSI color model


 H : hue
 S : saturation
 I : intensity

Conceptual relationships between the RGB


and HSI color models. 61
2.2.2 COLOR MODELS

2 THE HSI COLOR MODELS

Hue and saturation in the HSI color model. The dot is any color point. The
angle from the red axis gives the hue. The length of the vector is the
saturation. The intensity of all colors in any of these planes is given by the
position of the plane on the vertical intensity axis.
62
2.2.2 COLOR MODELS
2 THE HSI COLOR MODELS

The HSI color model based on triangular color planes


63
2.2.2 COLOR MODELS
2 THE HSI COLOR MODELS

The HSI color model based on circular color planes


64
2.2.2 COLOR MODELS
3 CONVERTING COLOR FROM RGB TO HSI
 Converting colors from RGB to HIS
 Hue component
 1 
  if B  G 1  2
{( R  G ) + ( R  B )} 
H    cos  1/ 2 
360   if B  G  +  
2
 {( R G ) ( R B )(G B )} 
 
 Saturation component
3
S  1 [min( R, G , B)]
( R + G + B) RGB values have been
normalized to the range [0,1]
 Intensity component Angle  is measured with
1 respect to the red axis
I  ( R + G + B)
3 Hue can be normalized to the
range [0, 1] by dividing by
360c 65
2.2.2 COLOR MODELS
4 CONVERTING COLOR FROM HSI TO RGB

 Converting colors from HSI to RGB


 Three sectors of interest, corresponding to the
1200 intervals in the separation of primaries
 RG sector (0  H  120 )

B  I (1  S )
 S cos H 
R  I 1 + 
 cos(60 o
 H ) 
G  3I  ( R + B )

66
2.2.2 COLOR MODELS
4 CONVERTING COLOR FROM HSI TO RGB

 
 GB sector (120  H  240 )  BR sector (240  H  360 )

H  H  120o H  H  240o
R  I (1  S ) G  I (1  S )
 S cos H   S cos H 
G  I 1 +  B  I 1 + 
 cos(60 o
 H )   cos(60 o
 H ) 
B  3I  ( R + G ) R  3I  (G + B)

67
2.2.2 COLOR MODELS
4 CONVERTING COLOR FROM HSI TO RGB
 Example
 The HSI values
corresponding to
the image of the
RGB color cube

68
2.2.2 COLOR MODELS
4 CONVERTING COLOR FROM HSI TO RGB
 Manipulating HSI component images

69
2.2.2 COLOR MODELS
4 CONVERTING COLOR FROM HSI TO RGB

70
2.2.3 PSEUDOCOLOR IMAGE PROCESSING

 Pseudocolor image processing (or false color)


 Pseudocolor image processing consists of
assigning colors to gray values based on a
specified criterion
 The principal use of pseudocolor
 Human visualization
 Interpretation of gray-scale events
 Principal motivation for using color
 Humans can discern thousands of color
shades and intensities, compared to only
two dozen or so shades of gray
71
2.2.3 PSEUDOCOLOR IMAGE PROCESSING

1. Intensity Slicing
 Intensity slicing can be expressed by the
following equation
f ( x, y )  ck if f ( x, y )  Vk

72
2.2.3 PSEUDOCOLOR IMAGE PROCESSING

73
2.2.3 PSEUDOCOLOR IMAGE PROCESSING

74
2.2.3 PSEUDOCOLOR IMAGE PROCESSING

2. INTENSITY TO COLOR TRANSFORMATIONS


 Basic concept of the grey level to color
transformation
 Performing three independent transformations on the
gray level of any input pixel

75
2.2.3 PSEUDOCOLOR IMAGE PROCESSING

2. INTENSITY TO COLOR TRANSFORMATIONS

76
2.2.3 PSEUDOCOLOR IMAGE PROCESSING

2. INTENSITY TO COLOR TRANSFORMATIONS

77
2.2.4 BASICS OF FULL-COLOR IMAGE
PROCESSING

 Full-color image processing approaches fall into


two major categories:
 Process each grayscale component image individually

 work with color pixels directly

 A pixel at (x,y) is a vector in the color space


 RGB color space

 cR ( x, y )   R ( x , y ) 
  
c( x, y )   cG ( x, y )   G ( x, y )  
 cB ( x, y )   B ( x, y ) 
78
2.2.4 BASICS OF FULL-COLOR IMAGE
PROCESSING

Spatial neighborhoods for grayscale and RGB color images.


Observe in (b) that a single pair of spatial coordinates (x, y),
addresses the same spatial location in all three images.

79
2.2.5 COLOR TRANSFORMATIONS

1. FORMULATION

Color transformations for multispectral images using the


general expression

si  Ti (r1 , r2 ,..., rn ) , i  1,2,..., n


where n is the total number of component images;
ri are the intensity values of the input component images;
si are the spatially corresponding intensities in the output
component images;
and Ti are a set of transformation or color mapping
functions that operate on ri to produce si.
80
2.2.5 COLOR TRANSFORMATIONS

 In the HIS color space, this can be done with the


simple transformation
s 3  kr3 , where 0  k  1
 In the RGB color space, three components must be
transformed:
si  kri i  1,2,3.
 The CMY space requires a similar set of tranfomations:

si  kri + (1  k ), i  1,2,3.
81
2.2.5 COLOR TRANSFORMATIONS

A full-color image and its various color-space components.


2.2.5 COLOR TRANSFORMATIONS

A full-color
image and its
various color-
space
components.

83
2.2.5 COLOR TRANSFORMATIONS

(b)
(a)

(c) (d) (e) (f) (g) (h)


Adjusting the intensity of an image using color transformations. (a) Original image. (b)
Result of decreasing its intensity by 30% (i.e., letting k  0 7 . ). (c) The required RGB
mapping function. (d)–(e) The required CMYK mapping functions. (f) The required CMY
mapping function. (g)–(h) The required HSI mapping functions.
2.2.5 COLOR TRANSFORMATIONS

2. COLOR COMPLEMENTS
 Complements : the hues directly opposite one another
on the color circle.
 Color complements are useful for enhancing detail that is
embedded in dark regions of a color image.

Color
complements on
the color circle.
2.2.5 COLOR TRANSFORMATIONS

Color
complement
transformations.
(a) Original image.
(a) (b) (b) Complement
transformation
functions.
(c) Complement
of (a) based on
the RGB mapping
functions.
(d) An approximation
(c) of the RGB
(d) complement using
HIS transformations.
2.2.5 COLOR TRANSFORMATIONS

3. COLOR SLICING

 Highlighting a specific range of colors in an image is


useful for separating objects from their surroundings.
 The basic idea
 Display the colors of interest so that they stand out from the
background
 Use the region defined by the colors as a mask for further
processing
2.2.5 COLOR TRANSFORMATIONS

 The simplest ways to “slice”


 To map the colors outside some range of interest to a
nonprominent neutral color
 If the colors of interest are enclosed by a cube,

  W
0.5 , if  rj  a j   , i  1, 2, , n
si    2  any 1 j  n
r , otherwise
i

 If a sphere is used to specify the colors of interest,


 n


si  
0 . 5 , if 
j 1
( r j  a j ) 2
 R0 , i  1, 2,  , n
2

r , otherwise
i
2.2.5 COLOR TRANSFORMATIONS

prototype color prototype color


Sphere region Cube region

89
2.2.5 COLOR TRANSFORMATIONS

(a) (b)
Color-slicing transformations that detect (a) reds within an RGB cube of
width W = 0 2549 centered at (0.6863, 0.1608, 0.1922), and (b) reds within
an RGB sphere of radius 0.1765 centered at the same point. Pixels
outside the cube and sphere were replaced by color (0.5, 0.5, 0.5).

You might also like