You are on page 1of 63

Digital Image Processing Using Matlab

Haris Papasaika-Hanusch
Institute of Geodesy and Photogrammetry, ETH Zurich
haris@geod.baug.ethz.ch
Digital Image Processing Using Matlab 2
Images and Digital Images

A digital image differs from a photo in that the values are all
discrete.

Usually they take on only integer values.

A digital image can be considered as a large array of discrete


dots each of !hich has a brightness associated !ith it. "hese
dots are called picture elements or more simply pixels.

"he pi#els surrounding a given pi#el constitute its


neighborhood A neighborhood can be characteri$ed by its
shape in the same !ay as a matri#% !e can speak of a &#&
neighborhood or of a '#( neighborhood.

Digital Image Processing Using Matlab &
Digital Image Processing Using Matlab )
Aspects of Image Processing

Image Enhancement: Processing an image so that the result


is more suitable for a particular application. *sharpening or de+
blurring an out of focus image highlighting edges improving
image contrast or brightening an image removing noise,

Image Restoration: "his may be considered as reversing the


damage done to an image by a kno!n cause. *removing of blur
caused by linear motion removal of optical distortions,

Image Segmentation: "his involves subdividing an image into


constituent parts or isolating certain aspects of an image.
*finding lines circles or particular shapes in an image in an
aerial photograph identifying cars trees buildings or roads.
Digital Image Processing Using Matlab '
Types of Digital Images

inary: -ach pi#el is .ust blac! or "hite. /ince there are only
t!o possible values for each pi#el *01, !e only need one bit
per pi#el.

#rayscale: -ach pi#el is a shade of gray normally from $


*black, to %&& *!hite,. "his range means that each pi#el can be
represented by eight bits or e#actly one byte. 2ther
greyscale ranges are used but generally they are a po!er of %.

Tr'e (olor or R#% -ach pi#el has a particular color3 that color
is described by the amount of red green and bl'e in it. If each
of these components has a range 042'' this gives a total of
%&)
*
different possible colors. /uch an image is a 5stack6 of
three matrices3 representing the red green and bl'e values
for each pi#el. "his means that for every pi#el there correspond
& values.
Digital Image Processing Using Matlab 7
inary Image
Digital Image Processing Using Matlab (
#rayscale Image
Digital Image Processing Using Matlab 8
(olor Image
Digital Image Processing Using Matlab 9
#eneral (ommands

imread% :ead an image

fig're% creates a figure on the screen.

imsho"+g,% !hich displays the matri# g as an image.

pix-al on% turns on the pi#el values in our figure.

impixel+i./,% the command returns the value of the pi#el *i.,

iminfo% Information about the image.


Digital Image Processing Using Matlab 10
(ommand 0indo"
Digital Image Processing Using Matlab 11
Data Types
Digital Image Processing Using Matlab 12
Image Information
Digital Image Processing Using Matlab 1&
it Planes

;reyscale images can be transformed into a se<uence of binary


images by breaking them up into their bit1planes.

=e consider the grey value of each pi#el of an 8+bit image as an 8+


bit binary !ord.

"he $th bit plane consists of the last bit of each grey value.
/ince this bit has the least effect *least significant bit plane,.

"he 2th bit plane consists of the first bit in each value *most
significant bit plane.
Digital Image Processing Using Matlab 1)
Initial Image
Digital Image Processing Using Matlab 1'
it Plane $
Digital Image Processing Using Matlab 17
it Plane 3
Digital Image Processing Using Matlab 1(
it Plane 2
Digital Image Processing Using Matlab 18
Spatial Resol'tion

Spatial resol'tion is the density of pi#els over the image% the


greater the spatial resolution the more pi#els are used to
display the image.

4al-e the si$e of the image% It does this by taking out every
other ro! and every other column thus leaving only those
matri# elements !hose ro! and column indices are even.

Do'ble the si$e of the image% all the pi#els are repeated to
produce an image !ith the same si$e as the original but !ith
half the resolution in each direction.
Digital Image Processing Using Matlab 19
Interpolation
Digital Image Processing Using Matlab 20
Extrapolation
Digital Image Processing Using Matlab 21
Arithmetic 5perations

"hese operations act by applying a simple function y>f*#, to


each gray value in the image.

/imple functions include adding or s'btract a constant value


to each pi#el% y > #?@ *imadd imsubtract,

M'ltiplying each pi#el by a constant% y > @A# *immultiply


imdivide,

(omplement% Bor a grayscale image is its photographic


negative.
Digital Image Processing Using Matlab 22
Addition 1 S'btraction
Digital Image Processing Using Matlab 2&
M'ltiplication1Di-ision
Digital Image Processing Using Matlab 2)
(omplement
Digital Image Processing Using Matlab 2'
Addition
Image: J
Image: J+!
Digital Image Processing Using Matlab 27
S'btraction
Image: J
Image: J-"!
Digital Image Processing Using Matlab 2(
M'ltiplication
Image: J
Image: J#$
Digital Image Processing Using Matlab 28
Di-ision
Image: J
Image: J%
Digital Image Processing Using Matlab 29
(omplement
Image: J
Image: ""-J
Digital Image Processing Using Matlab &0
4istograms

;iven a grayscale image its histogram consists of the


histogram of its gray levels3 that is a graph indicating the
number of times each gray level occurs in the image.

=e can infer a great deal about the appearance of an image


from its histogram.

In a dar! image the gray levels !ould be clustered at the lo!er


end

In a 'niformly bright image the gray levels !ould be clustered at


the upper end.

In a "ell contrasted image the gray levels !ould be !ell spread


out over much of the range.

Problem% ;iven a poorly contrasted image !e !ould like to


enhance its contrast by spreading out its histogram. "here are
t"o !ays of doing this.
Digital Image Processing Using Matlab &1
4istogram Stretching +(ontrast Stretching,

Poorly contrasted image of range CabD

=e can stretch the gray levels in the center of the range out by
applying a piece!ise linear function

"his function has the effect of stretching the gray levels CabD to
gray levels CcdD !here aEc and dFb according to the e<uation%

imad.ust*ICabDCcdD,

Pi#el values less than c are all converted to c and pi#el values
greater than d are all converted to d.
j=
cd
ba
iac
Digital Image Processing Using Matlab &2
4istogram Stretching
Digital Image Processing Using Matlab &&
efore 4istogram Stretching
Digital Image Processing Using Matlab &)
After 4istogram Stretching
Digital Image Processing Using Matlab &'
4istogram E6'ali7ation

"he trouble !ith the previous method of histogram stretching is


that they re<uire user input.

Gistogram e<uali$ation is an entirely automatic procedure.

/uppose an image has L different gray levels 0,1,2,...,1-L and


that gray level i occurs n
i
times in the image. /uppose also that
the total number of pi#els in the image is n so that
n
0
+n
1
+n
2
+...n
L
=n. "o transform the gray levels to obtain a
better contrasted image !e change gray level i to%

and this number is rounded to the nearest integer.

A roughly e<ual number of pi#els is mapped to each of the L


levels so that the histogram of the output image is
appro#imately flat.
Digital Image Processing Using Matlab &7
efore 4istogram E6'ali7ation
Digital Image Processing Using Matlab &(
After 4istogram E6'ali7ation
Digital Image Processing Using Matlab &8
Thresholding

Single thresholding% A grayscale image is turned into a binary


image by first choosing a gray level T in the original image and
then turning every pi#el black or !hite according to !hether its
gray value is greater than or less than T.

A pi#el becomes !hite if its gray level is > T

A pi#el becomes black if its gray level is <= T

Double thresholding% Gere !e choose t!o values "1 and "2 and
apply a thresholding operation as%

A pi#el becomes !hite if its gray level bet!een T1 and T2

A pi#el becomes black if its gray level is other!ise


Digital Image Processing Using Matlab &9
Thresholding
Digital Image Processing Using Matlab )0
Spatial 8iltering

Move a 5mas!6% a rectangle *usually !ith sides of odd length,


or other shape over the given image.

A ne! image !hose pi#els have gray values calculated from the
gray values under the mask.

"he combination of mask and function is called filter.

Hinear function of all the gray values in the mask then the filter
is called a linear filter.

/patial filtering re<uires & steps%


1.position the mask over the current pi#el
2.form all products of filter elements !ith the corresponding elements
of the neighborhood
&.add up all the products.

"his must be repeated for every pi#el in the image.

filter2*filterimageshape,
Digital Image Processing Using Matlab )1
Mas!s
Digital Image Processing Using Matlab )2
8iltering
0or!ing
8lo"
Digital Image Processing Using Matlab )&
8re6'encies9 :o" and 4igh Pass 8ilters

8re6'encies are the amount by !hich grey values change !ith


distance.

4igh fre6'ency components are characteri$ed by large


changes in grey values over small distances3 *edges and noise,

:o" fre6'ency components are parts characteri$ed by little


change in the gray values. *backgrounds skin te#tures,

4igh pass filter% if it 5passes over6 the high fre<uency


components and reduces or eliminates lo! fre<uency
components.

:o" pass filter% if it 5passes over6 the lo! fre<uency


components and reduces or eliminates high fre<uency
components.
Digital Image Processing Using Matlab ))
#a'ssian 8ilters

;aussian filters are a class of lo!+pass filters all based on the


;aussian probability distribution function%

!here is the standard deviation% a large value of produces


to a flatter curve and a small value leads to a 5pointier6
curve.

Ilurring -ffect
Digital Image Processing Using Matlab )'
#a'ssian 8ilters
Digital Image Processing Using Matlab )7
#a'ssian 8ilters
Digital Image Processing Using Matlab )(
;oise

Joise is any degradation in the image signal caused by


e#ternal disturbance.

Salt and pepper noise% It is caused by sharp sudden


disturbances in the image signal3 it is randomly scattered !hite
or black *or both, pi#els. It can be modeled by random values
added to an image

#a'ssian noise% is an ideali$ed form of !hite noise !hich is


caused by random fluctuations in the signal.

Spec!le noise% It is a ma.or problem in some radar


applications. It can be modeled by random values multiplied by
pi#el values.

Digital Image Processing Using Matlab )8


Salt < Pepper ;oise
Digital Image Processing Using Matlab )9
#a'ssian ;oise
Digital Image Processing Using Matlab '0
Spec!le ;oise
Digital Image Processing Using Matlab '1
& 'oti(ation: detect changes
change in the pi)e* (a*ue *arge gradient
Gradient
operator
image
Thresho*ding
edge
map
x(m,n)
g(m,n)
I(m,n)

'

>

otherwise
th n m g
n m I
!
+ , , - + .
, , -
We can implement those two steps by basic MATLAB functions.
Edge Detection
Digital Image Processing Using Matlab '2
./ Pre0itt operator / 1o2e* operator
1
1
1
]
1

. ! .
. ! .
. ! .
1
1
1
]
1


. . .
! ! !
. . .
1
1
1
]
1

. ! .
!
. ! .
1
1
1
]
1


. .
! ! !
. .
(ertica*
hori3onta*
(ommon Edge 5perators
Digital Image Processing Using Matlab '&
(anny Edge Detector

:o" error rate of detection

=ell match human perception results

#ood locali7ation of edges

"he distance bet!een actual edges in an image and the edges


found by a computational algorithm should be minimi$ed

Single response

"he algorithm should not return multiple edges pi#els !hen


only a single one e#ists
Digital Image Processing Using Matlab ')
Edge Detectors
Color Image
Grayscale Image
Digital Image Processing Using Matlab ''
Edge Detectors
Sobel
Canny
Digital Image Processing Using Matlab '7
(olor Images

A color model is a method for specifying colors in some


standard !ay. It generally consists of a &D coordinate system
and a subspace of that system in !hich each color is
represented by a single point.

R#% In this model each color is represented as & values R G


and B indicating the amounts of red green and blue !hich
make up the color.

4S=%

Gue% "he 5true color6 attribute *red green blue orange yello!
and so on,.

/aturation% "he amount by !hich the color as been diluted !ith


!hite. "he more !hite in the color the lo!er the saturation.

Kalue% "he degree of brightness% a !ell lit color has high intensity3 a
dark color has lo! intensity.
Digital Image Processing Using Matlab '(
(olor Image
Digital Image Processing Using Matlab '8
(olor (on-ersion
Digital Image Processing Using Matlab '9
Initial (olor Image
Digital Image Processing Using Matlab 70
R# (olor Space
RED GREEN
BLE
Digital Image Processing Using Matlab 71
4S= (olor Space
!E
S"#R"#I$N %"LE
Digital Image Processing Using Matlab 72
(5:5R (5MP5SITE
"ster & "ster '
"ster (
Digital Image Processing Using Matlab 7&
(5:5R (5MP5SITE
"ster &)()'
"ster ()&)' "ster ')()&

You might also like