You are on page 1of 43

TITLE SLIDE

I nt r oduct i on t o MATLAB and i t s Comput at i onal


Power s i n I mage Pr ocessi ng
By :-
b l ue i nk i nf ot ec h p vt . l t d .
www.blueink.in
Join us at facebook:-
blueink infot ech
COM PANY INTRODUCTION
b l ue i nk i nf ot ec h p vt . l t d . has st ar t ed i t s
j our ney i n ear l y 2008. Bl ue Ink i s an i ncubat ee
company of Technol ogy Busi ness Incubat or,
KIET.
Companys w or k domai ns ar e sof t war e
devel opment , w eb devel opment , pr oj ect
devel opment and t rai ni ng, e-l ear ni ng and
cont ent management , Embedded Syst ems.
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Out l i ne
Par t I: Int r oduct i on and Over vi ew (Case St udy)
Par t II: M ATLAB Deskt op
Par t III: Types of Fi l es
Par t IV: M at r i x M ani pul at i ons, Common
Funct i ons, Pl ot s i n M ATLAB
Par t V: Image Pr ocessi ng Commands
Par t VI: M odel Demonst rat i on
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
What i s M ATLAB?
M ATLAB (M ATr i x LABorat or y) i s a hi gh-per f or mance l anguage f or
t echni cal comput i ng. It i s an i nt eract i ve syst em w hose basi c dat a
el ement i s an ar ray t hat does not require dimensioning. Al l ows t o
sol ve many t echni cal comput i ng pr obl ems, exampl es of w hi ch
i ncl ude:
M at r i x mani pul at i on
Fi ndi ng t he r oot s of pol ynomi al s
Di gi t al si gnal pr ocessi ng appl i cat i ons (t ool box)
Pl ot t i ng: x-y and pol ar, 3D graphi cs
Par t i cul ar l y hel pf ul f or :
Al gor i t hm devel opment ,
M odel i ng, si mul at i on, and pr ot ot ypi ng,
Dat a acqui si t i on
Dat a anal ysi s, expl orat i on, and vi sual i zat i on,
Appl i cat i on devel opment , i ncl udi ng graphi cal user i nt er f ace bui l di ng.
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Level s of Image Pr ocessi ng
Ther e ar e no cl ear -cut boundar i es i n t he
cont i nuum f r om i mage pr ocessi ng at one end
t o comput er vi si on at t he ot her. However, a
usef ul paradi gm i s t o consi der t hee t ypes of
comput er i zed pr ocesses:
Low level processes
M id level processes
High level processes
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Low l evel pr ocesses
A l ow l evel processes i nvol ve pr i mi t i ve operat i ons, such as
i mage pr eprocessi ng t o r educe noi se, cont rast
enhancement , and i mage shar peni ng. A l ow-l evel process i s
charact er i zed by t he f act t hat bot h i t s i nput s and out put s
t ypi cal l y ar e i mages.
M i d-l evel processes on i mages i nvol ve t asks such as
segment at i on (par t i t i oni ng an i mage i nt o r egi ons or
obj ect s), descr i pt i on of t hose obj ect s t o r educe t hem t o a
f or m sui t abl e f or comput er processi ng, and cl assi f i cat i on
(r ecogni t i on) of i ndi vi dual obj ect s. A mi d-l evel process i s
charact er i zed by t he f act t hat i t s i nput s general l y ar e
i mages, but i t s out put s ar e at t r i but es ext ract ed f rom t hose
i mages (e.g. edges, cont ours, and t he i dent i t y of i ndi vi dual
obj ect s).
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Hi gh Level Pr ocesses
Hi gh l evel pr ocessi ng i nvol ves maki ng sense
of an ensembl e of r ecogni zed obj ect s, as i n
i mage anal ysi s, and, at f ar end of cont i nuum,
per f or mi ng t he cogni t i ve f unct i ons nor mal l y
associ at ed w i t h human vi si on.
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Appl i cat i ons of Image Pr ocessi ng
Weat her f or cast i ng
M achi ne vi si on measur i ng di st ance of obj ect s
Obj ect det ect i on
Fi ndi ng an odd pr oduct on t he conveyor bel t
VIDEO DEM O
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
M ATLAB Syst em
M ATLAB syst em consi st s of f i ve mai n par t s
Devel opment Envi r onment
Set of t ool s and f aci l i t i es t hat hel p you use M ATLAB f unct i ons and
f i l es.
M ATLAB M at hemat i cal Funct i on Li br ar y
Col l ect i on of f unct i ons l i ke sum, si ne, cosi ne, and compl ex
ar i t hmet i c, mat r i x i nver se, mat r i x ei genval ues, and f ast Four i er
t ransf or ms.
The M ATLAB Language
Hi gh-l evel mat r i x/ ar ray l anguage wi t h cont r ol f l ow st at ement s,
f unct i ons, dat a st r uct ur es, i nput / out put , and obj ect -or i ent ed
pr ogrammi ng f eat ur es.
Gr aphi cs
Pr ovi des ext ensi ve f aci l i t i es f or di spl ayi ng vect or s and mat r i ces as
graphs, as wel l as annot at i ng and pr i nt i ng t hese graphs.
Appl i cat i on Pr ogr am Int er f ace (API)
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
M ATLAB Deskt op
When you st ar t M ATLAB, M ATLAB deskt op appears,
cont ai ni ng t ool s (graphi cal user i nt er f aces) f or managi ng
f i l es, var i abl es, and appl i cat i ons associ at ed w i t h M ATLAB.
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Hel p i n M ATLAB
>> hel p <f unct i onname>
Shows hel p document f or a gi ven f unct i on
Exampl e: help mean
>> l ookf or <keywor d>
Sear ches al l t he hel p document s f or a gi ven
keywor d
Exampl e: lookfor average
>> demo
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Types of Fi l es
.m f i l e - command w i ndow i s used t o execut e
si ngl e command. But i f i t i s r equi r ed t o
execut e/ save a pr ogram, we need t o generat e
a mat l ab pr ogrammi ng f i l e w hi ch i s saved as
xyz.m (mat f i l e)
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
SIM ULINK
Si mul i nk

sof t war e model s, si mul at es, and anal yzes


dynami c syst ems. It enabl es you t o pose a quest i on about a
syst em, model t he syst em, and see what happens.
Wi t h Si mul i nk, you can easi l y bui l d model s f rom scrat ch, or
modi f y exi st i ng model s t o meet your needs. Si mul i nk
suppor t s l i near and nonl i near syst ems, model ed i n
cont i nuous t i me, sampl ed t i me, or a hybr i d of t he t wo.
Syst ems can al so be mul t i rat e havi ng di f f er ent par t s t hat
ar e sampl ed or updat ed at di f f er ent rat es.
Thousands of sci ent i st s and engi neers around t he wor l d use
Si mul i nk t o model and sol ve r eal probl ems i n a var i et y of
i ndust r i es, i ncl udi ng:
Aerospace and Def ense
Aut omot i ve
Communi cat i ons
El ect roni cs and Si gnal Processi ng
M edi cal Inst r ument at i on
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Var i abl es: Scal ar s, Vect or s and
M at r i ces
Real Scalars
>> x = 5
x = 5
Complex Scalars
>> x = 5+10j %5+10i wor ks, as does 5+10* j
x =
5.0000 +10.0000i
Row Vect or (1 x 3)
>> x = [ 1 2 3 ]
x =
1 2 3
Column Vect or ( 3 x 1)
>> x = [ 1 ; 2 ; 3 ] ; % ; supresses out put
>> x
x =
1
2
3
M at rix (3 x 3)
>> x = [ 1 2 3 ; 4 5 6 ; 7 8 9 ]
x =
1 2 3
4 5 6
7 8 9
Not e: Variable Names are case sensit ive
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Gener at i ng Vect or s and t he Col on Oper at or
>> x = [ 0 : 0.2 : 1 ] % 0 t o 1 i n i ncr ement s of 0.2
x =
0 0.20 0.40 0.60 0.80 1.00
>> x = l i nspace(0, 1, 6) % 6 poi nt s f r om 0 t o 1 on a l i near scal e
x =
0 0.20 0.40 0.60 0.80 1.00
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Generat i ng M at r i ces
>> B = [ 1 2 ; 8 9 ]
ans =
1 2
8 9
>> ones( 2,2) % generat es an all ones 2 x 2 mat rix
ans =
1 1
1 1
>> zeros( 2,3) % generat es an all zero 2 x 3 mat rix
ans =
0 0 0
0 0 0
>> rand( 3,3) % generat es a random 3 x 3 mat rix
ans =
0.4447 0.9218 0.4057
0.6154 0.7382 0.9355
0.7919 0.1763 0.9169
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Accessi ng M at r i x El ement s
>> A= [ 1 2 3 ; 4 5 6 ; 7 8 9] ;
>> x = A ( 1, 3 ) %A(<row >,<column>)
x =
3
A =
1 2 3
4 5 6
7 8 9
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Compl ex Number Operat i ons
>> x = 3+4j
>> abs(x) %Absol ut e val ue.
x = 5
>> angl e(x) %Phase angl e (i n r adi ans).
x = 0.9273
>> conj (x) %Compl ex conj ugat e.
x = 3-4j
>> i mag(x) %Compl ex i magi nar y par t .
x = 4
>> r eal (x) %Compl ex r eal par t .
x = 3
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Some Usef ul Funct i ons
Some usef ul mat h f unct i ons:
si n(x), cos(x), t an(x), at an(x), exp(x), l og(x), l og10(x), sqr t (x)
>> t = [ 0 : 0.01 : 10 ] ;
>> x = si n ( 2 * pi * t );
Some usef ul mat r i x and vect or f unct i ons:
>> si ze (A)
ans =
3 3
>> l engt h ( t )
ans =
1001
A =
1 2 3
4 5 6
7 8 9
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
What i s sum(A' )' ?
A =
1 2 3
4 5 6
7 8 9
M or e Operat or s and Funct i ons
For vect ors, SUM ( X) is t he sum of t he element s of X. For mat rices, SUM ( X) is a row vect or w it h
t he sum over each column.
>> sum ( A )
ans =
12 15 18
>> sum ( ans ) % equivalent t o sum( sum( A) )
ans =
45
>> A % equivalent t o t ranspose( A)
ans =
1 4 7
2 5 8
3 6 9
>> diag( A)
ans =
1
5
9
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Root s of Pol ynomi al s
Fi nd t he r oot s of t he pol ynomi al : 13 x
3
+ 25 x
2
+ 3 x + 4
>> C = [ 13 25 3 4] ;
>> r = r oot s(C)
r =
-1.8872
-0.0179 + 0.4034i
-0.0179 - 0.4034i
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
>> x = [ 0 : 0.001 : 2* pi ] ;
>> y = si n ( x );
>> pl ot (x,y) ;
Cont i nuous Ti me Pl ot s
0 1 2 3 4 5 6 7
-1
-0.5
0
0.5
1
The pl ot f unct i on has di f f er ent f or ms, dependi ng on t he i nput ar gument s.
If y i s a vect or, pl ot (y) pr oduces a pi ecewi se l i near graph of t he el ement s
of y ver sus t he i ndex i t s el ement s. If you speci f y t wo vect or s as ar gument s,
pl ot (x,y) pr oduces a graph of y ver sus x.
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Di scr et e Ti me Pl ot s St ems
St em f unct i on i s ver y si mi l ar t o pl ot . It i s used t o pl ot di scr et e t i me
sequences. For mor e i nf o: hel p st em
Exampl e:
>> k = [ 0 : 30 ] ;
>> x = si n ( k / 5 ) ;
>> st em ( k, x)
0 5 10 15 20 25 30
-1
-0.5
0
0.5
1
0 s k s 5
x

[

k

]
x [ k ] = sin ( k / 5 ) for 0 s k s 5
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
0 1 2 3 4 5 6 7
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
sin(x)
sin(x-.25)
sin(x-.5)
M ul t i pl e Dat a Set s i n One Graph
M ul t i pl e x-y pai r ar gument s cr eat e mul t i pl e graphs w i t h a si ngl e cal l
t o pl ot . For exampl e, t hese st at ement s pl ot t hr ee r el at ed f unct i ons
of x, each cur ve i n a separat e di st i ngui shi ng col or.
x = 0:pi / 100:2* pi ;
y = si n(x);
y2 = si n(x-.25);
y3 = si n(x-.5);
pl ot (x,y,x,y2,x,y3)
l egend(' si n(x)' ,' si n(x-.25)' ,' si n(x-.5)' )
The l egend command pr ovi des an easy
way t o i dent i f y t he i ndi vi dual pl ot s.
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Funct i on
Synt ax
f unct i on [ out 1, out 2, ...] = f unname(i n1, i n2, ...)
Descr i pt i on
f unct i on [ out 1, out 2, ...] = f unname(i n1, i n2, ...)
def i nes f unct i on f unname t hat accept s i nput s i n1,
i n2, et c. and r et ur ns out put s out 1, out 2, et c.
Demo Exampl e
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Pr eci ous Ti p 1
Not i ce t hat t he ar ray subscr i pt s i n M at l ab st ar t f rom 1
and not 0 as i s t he case i n C.
Il l ust rat i on:
>> A = [ 1 2 3 4] ;
>> A(0) % Thi s command w i l l r esul t i n synt ax er ror
The f i rst i ndex i s 1 and not 0.
>> A(1)
ans = 1
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Pr eci ous Ti p 2
Ti p 2: M ATLAB i s desi gned t o per f or m vect or operat i ons. Long f or -l oops on t he
ot her hand ar e not ef f i ci ent . You can see t hat by compar i ng t he f ol l ow i ng t wo pi eces
of code t hat do t he ver y same t hi ng: f i l l i ng an ar ray A w i t h 5s.
X = 5 * ones(10^ 7,1);
OR
Y = zer os(10^ 7,1);
f or i = 1 : l engt h(A)
Y(i ) = 5;
end
Tr y r unni ng t he above t wo pi eces of codes (r ed and bl ue one) i n M at l ab (Just copy and
past e on t he command pr ompt ). Compar e t he t i me i t t akes f or M at l ab t o execut e
t hem. What do you concl ude?
Not e: t he r esul t s of t wo pi eces of code ar e t he same!
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
IM AGES
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Pi xel co-or di nat e
The most conveni ent met hod f or expr essi ng l ocat i ons i n an
i mage i s t o use pi xel coor di nat es. In t hi s coor di nat e syst em,
t he i mage i s t r eat ed as a gr i d of di scr et e el ement s, or der ed
f r om t op t o bot t om and l ef t t o r i ght , as i l l ust r at ed by t he
f ol l owi ng f i gur e.
Pixel coordinat e syst em
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Image as M at r i ces
(
(
(
(

=
) 1 , 1 ( .... ) 1 , 1 ( ) 0 , 1 (
.. ..
) 1 , 1 ( .... ) 1 , 1 ( ) 0 , 1 (
) 1 , 0 ( .... ) 1 , 0 ( ) 0 , 0 (
) , (
N M f M f M f
N f f f
N f f f
y x f

Each el ement of t hi s ar ray i s cal l ed and i mage el ement , pi ct ur e el ement , pi xel or pel .
A M ATLAB i mage can be r epr esent ed as a M ATLAB mat r i x:
(
(
(
(

=
) , ( .... ) 2 , ( ) 1 , (
.. ..
) 1 , 1 ( .... ) 1 , 1 ( ) 1 , 2 (
) , 1 ( .... ) 2 , 1 ( ) 1 , 1 (
) , (
N M f M f M f
N f f f
N f f f
y x f

Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Bi nar y Image
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Image Pr ocessi ng Commands
Reading I mages
Images ar e r ead i nt o t he M ATLAB envi r onment usi ng f unct i on i mr ead, whose
synt ax i s
I mread( f ilename)
Her e, f i l ename i s a st r i ng cont ai ni ng t he compl et e name of t he i mage f i l e
(i ncl udi ng any appl i cabl e ext ensi on). For exampl e, t he command l i ne
>> f = imread ( f low er. jpg) ;
Reads t he JPEG i mage f l ower i nt o i mage ar ray f. The semi col on at t he end of
a command l i ne i s used by M ATLAB f or suppr essi ng out put . If a semi col on i s
not i ncl uded, M ATLAB di spl ays t he r esul t s of t he oper at i on(s) speci f i ed i n t hat
l i ne. Fi l e must be l ocat ed i n t he cur r ent di r ect or y or i n t he M ATLAB sear ch
pat h.
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Displaying I mages
>> imshow ( f )
>> imshow ( f low er. jpg)
Thi s command di spl ays t he i mage st or ed i n t he graphi cs f i l e. The f i l e must
cont ai n an i mage t hat can be r ead by i mr ead. The f i l e must be i n t he cur r ent
di r ect or y or on t he M ATLAB pat h.
>> w hos f
Name Si ze Byt es Cl ass At t r i but es
f 350x350x3 367500 ui nt 8
whos f ext ract basi c i nf or mat i on about t he i mage, and di spl ay i t .
Image Pr ocessi ng Commands
Writ ing I mages
Images ar e wr i t t en t o di sk usi ng f unct i on i mwr i t e, whi ch has t he f ol l owi ng
basi c synt ax:
imw rit e ( f, f ilename)
e. g. imw rit e( f, f low er1. png)
Her e, t he above command wr i t es f t o a png f i l e named f l ower 1.
If f i l ename cont ai ns no pat h i nf or mat i on , t hen i mwr i t e saves t he f i l e i n t he
cur r ent wor ki ng di r ect or y. M ost of t he wor k deal s wi t h JPEG or TIFF
i mages, so we f ocus at t ent i on her e on t hese t wo f or mat s.
Image Pr ocessi ng Commands
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
I mage compression
A mor e general i mwr i t e synt ax appl i cabl e onl y t o JPEG i mages i s
>> imw rit e ( f, f ilename, qualit y, q)
Wher e q i s an i nt eger bet ween 0 and 100 (t he l ower t he number t he hi gher
t he degradat i on due t o JPEG compr essi on).
In or der t o r educe st orage and t ransmi ssi on t i me, i t i s i mpor t ant t hat t he
i mages be compr essed as much as possi bl e whi l e not degradi ng t hei r
vi sual appearance beyond a r easonabl e l evel . In t hi s case r easonabl e
means no per cept i bl e f al se cont our i ng.
Image Pr ocessi ng Commands
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Compr essi on
f l ower.j pg (184kb)
f l ower 50.j pg ( 20 kb)
i mwr i t e(f, f l ower 50.j pg , qual i t y , 50)
f l ower 30.j pg ( 16 kb)
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Funct i ons
The f unct i on def i ni t i on l i ne has t he f or m:
Funct i on[ out put s] = name (i nput s)
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Pr oposed Pr oj ect s of Image Pr ocessi ng
Any obj ect shape & col or det ect i on.
To j udge si ze, shape & or i ent at i on of an obj ect .
Aut omat i c at t endance syst em usi ng i mage pr ocessi ng (f ace
r ecogni t i on).
Traf f i c l i ght cont r ol l er usi ng i mage pr ocessi ng (based upon no. of
vehi cl es on t he r oad).
M easur e t he di st ance of obj ect s f r om camera (obst acl e avoi dance).
Si gnat ur e r ecogni t i on.
Saf et y al ar m f or a dr i ver i n dr owsi ness condi t i on(based on eye
bl i nki ng rat e).
Secur i t y syst em.
Obj ect Tracki ng
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Obj ect Tracki ng
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Lane Depar t ur e Syst em
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
Car Tracki ng
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com
For f ur t her quer i es you can mai l me at -
ashut osh.r et hym@gmai l .com
Or cal l at - 9999645463
Prepared by : Ashut osh K. Agar wal
ashut osh.ret hym@gmai l .com

You might also like