Professional Documents
Culture Documents
37
t9
p3lEls sr ozrs 3lu e8erur ¡r{t eSurols 3tu Jo osodrnd áq} rol ezrs eli:
"{lrJEduJ
aql aJnpoi ot steltuoJ olu,fteurq JSn selg e8plur'lelouei uJ elqelr¿^e aulo¡¡c
sluaura,rolduu pu€ seinl€oJ alour pup erotu su Surpuedxa ,{lsnonurlnoc :q tr:
nl)as 3sn ur cle leql -sslg aSuurr jo sed.{t aq1 por:ad .ro top E reUB ,(1¡ensn pur'
elueuolu eq] urqlr,\\ pslprrpur sr elu oql Jo cd,{1 oq:¡ 'stuc1s,(s 8ur1e:cdo ,(ueru
ul selu eqt ,{uldsrp puu puel .{1}oa:ro: ot elqp cq o1 po:mbar ore sue¡8ord
cgnads 1er¡1 superu qlll,\\ 'se¡g .{:uurq e:e salg e?eur uorurrroJ lsoul ari-¡
solll 36eul l'9
'Irplep ur pa,ro¡dxa sr 'e8eur ue pue Jallu ¿ Jo uorlnloluo¡
CZ sr^lolur q:rq,tr '3ur:etlg e8eut ¡nrledg AV-11VI l Sursn sa8eurr sso¡o¡d
pue az,{¡uue ol suuJtrl snou¿^ eJnporlur ueql pue slprxroJ uoruuroc eroru
oql ur solu e8uurr etrep elu,\\ pue peer o1 ,\\otl uJ¿s[ IILU a,tr.tatduqr snp u1
'Jlqpsn pue alqrssocce o¡ou Surssa¡old aFeutt or¡uur ol sllo^Aqlel\
uro,U elqelre^p ele ,sexoqlool pc1lec suer?ord Jo suortJelloc cgrceds leqi
{.ror!\ Jo eoJ¿ tupuodur ur? qJns sr slql gv1lv¡l 3o serltltqedec eqt .{q
pslroddns IIe,r sr teql IIr{s lullutueqleur e sr Sursse¡o.td e3eru1 ,- elep oql rollr-I
pue llelndrueu o1 s¡r¡s Sursse:ord-¡euárs pue -sSerur selnber srq¿ . elep
alqusn Állecgrtuaros tJertxr o1 peutro3:ad aq lsnru IJo,{\ IEUotlrpp¿ :tuelJrlJns
lou sr errole e8uur u¿ Sur,teq ual3o clrnb 'Suueeut8rrJ pue ¡JuorJs rrJ
'solro ,\\eu ]JnJlsuoJ ueJ 1I lo
r's:lPLuJoJ
lurcraururor re¡ndod lsoru jo esn oleut uÉc,'gV'IJVtr{ pue'esn ur ,{¡uoturuor
selg eScuu Jo sod,{l ,(ueur e:e J-IJtlI sJeqlunu jo s,{e.r:n ol pollo^uo:r 'a r
'pezrlrBrp eq p¡noo ruer?o1or¡d rulU ¿ tsql po.ra^ooslp ls.rU,{ar¡t arurs sa¡g e?erur
lutr8rp jo onl€^ aql u,{\ouI a^pq sJourouoilsV alqrssod auroceq suorle8rlsa,rur
.loqlo puu c¡ucrcs Sultsa¡olur 'sa¡g a8eurr aql etelndrueur pue csn o1 ,(1r¡rqe
erll rpr^\ peurqruoJ uerl,u :sJrnlJld 1sn[ uer¡l e]orrr sr el¿p eSerur 3o acu€punq?
srqJ 'sn qlr,{\ punoJp elup Jo ser¡1ul;nb a?:u1 ,{:rur sn s}a[ leql ua1s,{s o8e:o1s
u spr,Lo-rd osle souoqd IIoJ suorsuorrtrp o,r\l ur cos eM pllo,tt eql e.r:ase:d pur:
arnldu: 1eq1 selgeieuu 3o qs?,lr u p:]pelJ sprl sl?rJrupa auoqd ¡1ar 3o csn eq1
burssecoJd obetul pue sobetul
g raldeqc
T
in bytes (B) or megabytes (MB). ln order to work u'ith graphics files, it is fname:'rec.:
important to understand that each color element, or pixel, is just a nuntber oL M - imreao ( :. ::-
a sct ol numbers, and a picture is r.rothing more than a matrix of numbers.2
lmagc files can be separated into two classes, raster and vector graphics. te¡ Separ.ale ::
Raster graphics arc typically a rectangular array of numbcrs that represent the redPt ane - i: -:
various colors in the image, with the fir'st pixel located in one comer olthe itnage greenP Lane - :-:
and then lollowing a row colun.m otder until the final pixel is reached. Raster bfue Pl ane : ::: -
graphics will be thc prirnary focus ol this chapter. Vector graphics, as the namc
implies, alc based on vectors used to represent positions of objects in the irnage
!¡ ? Dcne
plane. Compalcd to raster graphics, vector graphics make t¿rsks such as scaling,
rotation, and translation ol objects considerably easier; however, vector graphics The r¡r,::.-:,
are not as effcctive lor representing everyday images taken with current digital file in this ca s;
carrcras. Most display and printing dcvices work with raster infonnation. semicolon is r¡:
Fortunately. conversior.r from vector graphics to raster graphics is straightfor- returned in thitt -
n'ard. although raster images usually rcquire larger file sizcs thau vector images. ,n" a*""r1i6r.i rr:
Iu a rastcr image the overall color of each pixel is defined by a specific v¿rriables can b:
intensit¡r levcl lor each of the colors red (R), glccn (G), and blue (B). The intensity panel.
level is a numbcr typically between 0 and 255.2 Using this RGB model, tlie color The cottr er.
blue would be rcpresenled by the number triplet (0, 0. 255), red by (255, 0, 0) and by-column-b¡ -pi.
green by (0, 255, 0). Other colors, such as purplc (128, 128, 255), make use of would provide ar
intensity levels in each plane. Onc of the easiest rvirys to explore how colors are thc red, green. '
madc rip in images is io use a graphics program such as Microsof'tt Painl to matlix are listed
make a small, single-color image and then decompose the imagc into numbers. The pixel int
Some of the more common image or graphics hles that MATLAB is able to used lor mather
work with arc BMP. GIF, JPEG, PNG, TIFF, and thcre are many more. In MATLAB dctcr
this chapter we u'ill work with just two of these file typcs to introduce some ol require data t¡ ¡.,;
the basics of wolking with images. In most cases, the MATLAB Help will let unsigned integcr
you take the basic skills that wc introduce here and adapt them to work with mathematics. p..
other file fom.rats. Example 5.1 th.'
4
The MATLAB built-in function to read in an image file is rmread 1¡ .r'3 numbers with ¿
This function reads in an image file of a defincd lormat and places the values 2, and 3. The c.-
into a matrix. Example 5.1 shows how to use amr:ead O to load a bitmap file lrom color plar'::
and store it in a matrix as a set of numbers that can be uscd lor calculations. plane 3 is blr,r.-.
Several new idcas are included here that will be explained further. rnatrix M are in:
type double anc
Example 5.1 Use imread ( ) to load a file and separate out color planes. type double. :i
t!¡ M 5 1.m mathematical .:
? sr'rr 2 25 16 occur when inte
? Load a frle lo a vecLor. Should ther.
!ó? Hou se keep ing values in each..
cfear aff; cic; t clears the lrorkspace & command l',/indow using the :-:-
reconstructcd iil
!¡:. Load a fife to a matrix next section.
'lIoIlJeS lxeU
3rl1 rrr u,\\oqs Jq lll,r\ ss33o.rd srql ( ) af ffaur ! ql[.t\ po^es uorll polsnllsuoJ¡l
áq lsnu xlrletx euEld-oerqt clSurs áqt puP 'uorlJunJ o 8ru-!n eql 3uIS11
sJe83]ur peu8lsun ()1 {3€q pelio^uoc eq lsnru seclJlllru aql Jo qslre uI sánlP,\
Iecuelxnu cql 'alg € o1 Ir?q e8etul aql eA¿s 01 psau ¿ cq 3i3rll plnoqs
'pasn ar¿ senle^,reSelur u3rl,,!\ rnJJo
ul?J lpql sio-ria uorlpcunJl lnoqp uJacuos llloLlll,tr suollPJado lectleuteqleru
ur pesn eq upo sasuluru aueld roloc oqt nI plllp aql 'o¡qnop ad,{1 'saue
Surcg'lducs eql uI sru?u xt.r1cru cgtcads-loloJ E uI pelols pue alqnop ad,{t
elep eq] o1 pouJ^nos a:e puc ed,{1 PlEp .81uln, srll Jo .{ll¿nlul oJP t\l xlrlPr 'l:
oq] ur s3nle^ eq1 peluescrdc.t sI JqnJ roloi gCU srlt os 'an1q sr g suuld 'suorlelnJIP¡
pue 'ueer3 sr Z eunld 'c8erut :no.¡o eueld pe.l oql sI qclq,tt '1 aueld ro¡oc utol3 :¡g derutrq r'
suurnloc pu¿ s,\\oJ eql .Io ll¿ lJa[3s ol pJsn sf ( I ' : ' : ) l.J epo3 átll € pul? '¿ ssnlB^ 3q1 S.l
'l se pegrluopr c,ru scueld iolot ee,IrlJ ttotl¿ztueSro letreds e qll,rt s-Isqunu O P:= '
gtum Jo lJolq p sp I I xr.rt€r eqt olut popeol sr aJr¡ a8uut aql ¡ g eldruexE ¡.¡.,
uI lsol sr uortlltüroJul [Euol1ol?{.(uÉ st'} 'uolst^lp ,{1le¡nrrlred 's]tleuláq}€ru qlh{ llo.\\ Lrl
loJ luerua^uoJ lou sr lÉlII.roJ slql lnq'(,91lüln,.Io 81urn,) sreSalur pauStsun tel 1¡,n dlag
,{q paluase:da.r }seq rle ¿}ep e1r3 scrqde:g per.¡rcads aq ol sad,{l ulup e.ttnbe:
JO otUOS 3fr1¡
lou seop puu pelueserdel áq plnoqs ¿11?p otll ,'lrorl sáutullslep BV-IIVfAI u1 ::our iur'
- uoueurroJur flrsuslnr ro¡oo :pt,to-rd ol Jerller lnq sJllerueqleru JoJ pasn ()1 elqB sr g\
áq ot ls¿¡sd,{t tou sr sálg sctqderS eql ur po.¡ots uorleturoJtlr lsxtd eq¿ ' aqunu o1
,sIq g re8elur peuSrsun ol sJeJal qltq,t\',81uln, su polsll 3.IE t{u}elx ol ]ulud ¡ ]-lLr
l l eql ur senlpl olll lpqt aJrloN sen¡u.t .{ltsuatut ánlq pu€ 'uea:8 'pe: aqt eJ¿ sioloJ \\!
eJe ssupld € aql o-rJr[,\\'E x 0¿ x 0¿ suolsueullp Jo xllletu N ue epl^oid plno,tt
JO esn 3{eLU
:8erur roloc ¡axrd g¿ x g¿ e Surpuo¡ 'aldutexc log xt:1eur eueld-,(q-uun¡oc-,{q puP (0 '0 '!!.
{\ol e s0lll0l3 t\l YLI1?rü áql olul JIIJ dtr lg Jtll Jo uols.Ioi\uoo 3qJ loloJ erll 'leFr
'leuud
,{1tsua1ur -rq1
rl\opur^A pueruuroJ 3q1 olur ueql 3uld,{1 ,{q pat:adsur eq ueJ selqBLIP^ :rgrceds e ie-
escql laued aoedsl:o¡¡ ECII BV'IJV1\¡ eq] ur .{trldstp lll,tt tlottnrexe oql 'sa8¿u¡.rol¡:
ñuunp paleo:r s3lqrlue¡. tueJelJrp aql:o'pe1ut.td eq IIr,{\ ruII leq} uI peuin}o.r -roj1r¡8re:1s <
uoflúLuJoJur erll 'epoJ Jo Jnrl ¿ Jo pue 0q1 ruou pe^orual sI uoloJlruss 'lIoIlB LtrrO-J U i
rql Jl l IAtr
xrJluru e olur lrtPp 0q1 spPo,I pue elu dl lf, € ¡sec slql uI olq
1e1Érp ¡u:.i-lr',:
.¡o edfl cql pu€ aut€uellJ eql slndul sÉ se{Ét uoltJunJ o pe3-¡tLIr erlf scrqderi rotr
'3ur1ecs sr: q:
auoo 91 a8euu oql ur
etxPlr 3ri1 sP '
! I \F,'.' : )Iit) aTqnop: aueldanTq lels¿u pJr{Jr
! \(7,1i1| )t{) eTqnop - euel¿uae:6 :8eur aqt -¡t' .
!( lI' . ': )N) aTqnop: auETdpa,r eqt lu:sa:dr.r
s aue Td roToc afe.tredos +?ó 'scn¡dc:8 :rrt.
_ srsqurntr -l\
?
1(,dluq, aurpu] ) peo-rur : I^I .ro Jeqtunu ri
i ,duq'pa:. - oureuJ sI 1r 's3Jr"J srr
q9 5ulssecud abeul pue sedewl q taldeqC
Chapter 5 lnages and lmag.
I 11 1 11 11
I 11 1 11 111 11
1 11 111 11
1 111 11 -,ra n e
1 111 11
1 1
Erirnrpl.-:
1 1111 1 11 ar r ay and t.'; -
sum: C; sr 1; sc !;
Ícr r:2:3: rMar
'at c:2:3:cl'llax
-of s- :1
ior t: -1:1
sum: s,J.n + M (r+ s, c+t );
end
e 1ci €:
(sr, sc) - sun/ 9,'
x.-
1: l
sum: C; sc:sc', i; !óincr counte r
end Figure 5.2 A ::
sr:sr+1; sc I; :; with pixelation ¿-
informat on iLra :
-ond
'luo.tedde st uo[eltxtd o] onp uotleut.lo]ut
jo ssol eql'suotsuaultp lmtsÁqd elues aql ut u¡ oqs ueqM.uoDJnpa.t ozts pue uoBelaxtd qlt,4
(lq6u) a6eurl e x e eql ol (ga) ebeur OOt x 001 leurouo eql lo uosuedLuoc V 2.9 arnbrl
0€ oz 0r 00r 08 09 0t 0¿
CI
OI
'pe^erqc€ sr cZIs elu.to uorlnlosoJ peJrsep eql
Illun 3lU o8urur u9.ro xulpur l? uo sourrl IE.raAos unlel oq uuJ sseJold srqJ
Jr
'pepoeu raqurnu paxu e le 1es rq plnoJ lr lnq 'e8eurr lsrq orll.lo enle^
lexrd runurxeu aqt sr ¡cxrd eJuaJoJeJ srrlt o-raH (1'1) laxrd aql lu se8eurr o,n1
eql uoo,r\laq ecuere-¡o.r flrsua¡ur uoutrüoJ e sepr,r.o:d uollJes ,sllnsei,roqS, orll ur
eurJ lslu eqJ ' (Ierb) deuroToc uorlcun3 Surdduu ro¡oc alecs,{er8 eql Bulsn,{q
lre1q o1 seuol ,(e:3 qinorql elq,r ruor3 aSuu s.ro1o: 1eql Surueeru e1els,{e:8
ll ol pJus^uoc uaaq e^pq saiuur cq¿ pul?rxtrro3 O csobeurr er¡l Sursn sa:n8g
crqde:8 se pe,{e¡dsrp eJÉ slJs ptep o,\\t oqJ slcxrd euru eql Jo uortpruruns e
cpl,r.o.td sacrpur 1puú s rrJqt r¡lr,r ,sdoo¡ loJ, o,\\t lsul sq1 pue ,,{e:re ¡41 erp
q8nolp dels s¡Jrpur o pue I rrrqt qlr,u ,sdoo1 roJ, o,rt ls.lu eqJ .sdool g -¡ol
patsau -rnoJ qinolql p:qsqdurorce sr lsxrd relueJ rqt pue s:oqqSreu lsaleau
lqira rqt 8ur8e:e¡¿ pue ,{u-r:u cq1 qSno:q1 Surddels Jo poqteru eq.l.
'suorsueurrp
leur6r.io eql ]o =
llsie,\o Jurps eql 8ui^pq s¿ u,\\oqs oru so8urur qloq oJurs .s¡exrd r:F.re1
:,req o1 s-ruodde 1r¡3r.r sqt uo ,{e:le ,nau eql ¿ g 3rg ur uorlcun; ( ) c s abeur
¡ql Sursn pa1lo1d e:e s,{¿llp qtog ,{u.l:e ler ur eq1 ur slexrd euru 3o a8urc,ru
eql sr ,{prre ,lrau eql ul slcxrd aql 3o qJue álaq,r ,ozrs ,{utla pecnpe.t ,{11ee.ri
e sr tlnsei :r¡1 sloqqireu tselpáu áqt Sur8e:c¡.¿ pue lurod pJrqt ,,{.re^a
t¿ ,{ei-re oql q?no.rqt Surddals ,(q tos etpp oqt Jo ezls eql sáJnpái pue ,{¿llp
a,Ienbs p ur sJequnu tuopul?l Jo ,{er.te yerlrur up selpl g.g aldruexa
3UOC:
I (.{ef 6) deu.roTor j (N)csabeulr 1 (¿) arntrr__
I (,{e.rb ) deu¡roIoc I (r{) c s abEu.rr i ( 'i ) ernb r_
1(I,I)r^r: (I,I)N j((:)N)rpur- (I /T)¡,
slTnssf Moqs ?i:
g )etdeLtC
70 Chapter 5 lmages and lm¿.
mcthods. RGB. lias already been introduccd, Others include HSV and
K - 0.368
CMYK color nodcls, or tables that provide dillerer]t ways to var)' color.
These colol models pt'ovidc different ways to model color, but sincc the range This ls a
of color lcally doesn't changc very much to tlre obscrver. thcsc other determine u hi¡
Ícprcsentations are just transforms of other models. The transformatiol] the tht'ee coltrl:
between RGB and CMYK proceeds as fbllou's: be used to del:
defined as a c¡ .
/R G B\
nrrxl^-,^-.^-1.
either bc ll an::
K-l \ /\\ /\\ /\\/
(5.1)
MATL.IB :
color schente.
intensity 1e,,.-1 r
imagc, as thc i:-.:
(5.2) lront whitc to i.
IK
lor a figule is;
coior map ker .
5.5 Spatial Fi
(5.4) One of the mo:r
Thesc filters ¿i rc
1o smooth or sl-.
These equatior]s can bc constructed into a fturction that will return the ap¡rly these tú.
CMYK values lor an RGB input. This function is shown in Example 5.4. introduccd in Sr-,
size of the tll.-. ::
Spatial trlre:
Example 5.4 Use the conversion function for RGB to C|\4YK. i.e.. a spatiai da:.
functron lC, M, Y, K I : RGB2CYMK (R, G, B) a point. In Sec::,
-a;:¡ I'{ 5 4.rn smooth nois\ d¡:
!i SI\'T 2 26-16 filter did reduce ::
!¡ RGR -)> CI4YI{ The simplest f ur,.
!ó
'i Conve r s Lon sharpening. Sntt r
RGB: fR/255; G/255; B/2551 ; fliters tcnd ¡o cn:
K-1 rnax(RGB) ; tion of the filter :
c: (1-RGB(1) K) / (1-K) ; shows tlre o¡-ser::
M: (1-RGB(2) K) /(1 K); applications.: Th:
Y- (1 RGB (3 ) - K) / (1-K); lliter.2 In the h:-i
E i.i sharpening Lapla.-
I
#
oql tnq 'peJunouoJd ssol sr lcol]o Suruedftqs eql 'l < V loJ luerceldel Suruedreqs i
e Jo rruoJ er{l uI sr rettu eq} ¡I:v uoq/\\'rellu lsooq-q8rq 3q1 uI ¿ ro}lu
lsooq-q8rq € Jo ru:oJ eql ur pesserdxe sI xuleru Surued:eqs eq1 .'suorluoqdde
Suruad:uqs pue Surqloorus roJ xulerü Jollg eql 3o uoqezrue8ro eq] s,troqs
arnSg er¡1 3o eprs pueq-lqSrr eql pue 'los €l€p oql uo sseco.¡d rotrlg oql Jo uoq
-ezrue8ro eql s,{\oqs t S 3!C Jo eprs pueq-Uel aq¿ se8ps e¡u¿que 01 puot s.rállg
Surued-reqs e¡q,,lt's:e¡g 8uu-rnlq se u,trou{ osle are s:e11g Surqloous Suruod:¿qs
pue Surqloours eJe 1ás ¿lep eql 01 perTdde oq uec lpql suortounJ tse¡durrs sq¿
'suorsuárürp o,ul ur pssn 0q UEJ srallu r¿lrurs esrouJo s130]J0 eql aJnpel prp rá1lg
eql 'Álalolduroc peJeAoJeJ 1ou se,r pu8rs purSuo eql eIq¡A etep,{srou qloorus
ol pesn sp,lr lpql pecnpoJlur s",^\ rálfu Sur8e¡el¿ u¿ '€'¿ uorloas uI lurod e
Jo enle^ eql ol¿¡nclmar o1 slurod elep Surpunorms áql sesn lás elep ¡erleds e ' e r
lslexrd 3o ,{e¡¡e ue 01 uorllunJ leJq€ureqleru e ssqdde 3uue11g 1e4ed5
'e8erur er{l. Jo {oo[ eql ,(Jrpoiu o] s¡ esod:nd sql 'elu oqt Jo azrs
eql SuronpeJ Jo asodrnd aql 8ur^eq ueq] ráqleJ tnq '€'S uorlJes ur pecnporlur '¡ 9 e¡duer3
qceo.rdde eq1 ur pe^lolur ssoql 01 ru¡nurs Á:e,t ele suoDrunJ oseql ,{[dd€ eql uJnleJ IJr.\\
o1 Sursn aq [[r,r e,r leql s¡decuoc crs¿q eqJ 'e3¿ur ue usd:eqs :o qtoorus ol
pasn oq u¿J l¿ql suoflounJ lsorl¿uieqleru uuo3red o1 peuSrsep eJe sJellu eseql
's.ra11g (t E)
ler¡eds3o osn oql sr Surssaco:d a8erurlo spoqlaru l3oJrp lsoru eglJo euO
buue¡¡rg le¡eds 9'9
'suorlcunJ pele¡er-e8eur Sursn s:e no,( :e^.eueq,\\ á[qe¡e^e eq 1¡t,,lr sdeu.r rolo3 (s's)
's:aqlo Suoruu ',Jerürüns, pue '.1e[ '.reddoc, ere,{¡t o] sp:o,,n,{e¡ deru:o1oc
Ieuonrppu euos uorlcunJ O d€xrroloc eql Sursn pellojluoJ sr ernSg e :o3
duu roloc aq¿ sroloc fer3 3urue1:ep -¡o seues e q8norql lculq ol álrq,lt uro{ (¿ s)
seSueqr :oloc pa,(eldsrp orll ' l ot 0 uor3 se8uuqo an1e.t ,{1rsue1ur oql se 'o8elur
o¡ers,(e:8 e ur'qceo:dde pasn,{¡uouuroc stql.¡o elduexe ue sy'1e,r.e1 ,{1rsua1ur
eql uo pes€q laxrd e 3o rolo3 aql a8uuqr sdeu Joloo aseqJ 'sauráqcs ioloc
luareJ1rp ,{eldsrp tpqt suorldo deru roloc Jo raqunu e sepr,rord SV'IIV¡¡ (t
(: s)
l'pesn eq plnoc )atu LUJOJ oql Jo 'pesodsu€rl aq rorllrs
plnoc gDU Joqlre 'lolco^,\\or e áJo,{\ lrJr 'Je^e,^Aoq :rolma urunloJ e se peuUap
sr gCl{ l€ql ac4o¡1 a1du1 eq1 Jo onle^ runrurxeur eqt ourruJstep ol pesn áq
u€c uorlJunJ O xÉu¡ aql 1eq1 os xrrleur e¡8urs e olur peceld a:e sJoloo aelrlt aql uollBrIIloJsu¿Jl J
'eldurrs srql e{eur oJ 'lseq8rq sr g ro 'C '1¡ Jo senle^ eql Jo qcrq,tr ourruJotep Jáqlo oseql .l¡ u
ol peou op no,{ q8noql¡e 'uorsrá^uoJ pre,tr.ro31q3re:ls ,ften e sr srq¿ á8ueJ eql aJurs ln
':oJoc ,{¡¿,r o1 s i
pue ASH epnlru
88t'0 - t sseql Jo euo .p¡s
Lb9'A:L s:e e:eq¿ .o8eur
9tB'0-h oql e.raq,ü 'sa;eLur
0:a) 3SárlJ le,{or,\ ¡r{l
(S9, tZ, 9ET ) X¡{CZsgli : [x, I,r{, C] 6qruun¡ Jo sllnseE
,L dussaxu¿ a6eal pue sadewl I reldeqC
72 Chapter 5 Images and lmag..
where C(r, c) is an element of thc nen' matrix. / is a square filter matrix of size ri noRrn {= :
N-2nt- 1, and M holds the elemcnts being included ln the original irnage
matdx. ¿¿ Scan. ..:
The application of the 3 x 3 filter matrix to the data is shown in Fig. 5.3. s - ilocr (.i ,
rvhcre the first calculation has the filter centered on the in-rage data point r:R : slart, .
located at row - 2, colunn:2 or (2,2). By starting at this location rathcr for¡-s]-:r,:
than at the (I,1) location, all of rl.re filter elements are within the inage. Had iorc-:.
the proccss started at the point (l.l) in the imagc. the top row and lafJcft T:.',
]/l O 1{rllEluqns alEuj 1 I (s+il:s-c's+l:s :r)l,il-I U3[-JeJ puP \(rj
S-lr"¡¡: lf elS - c .iol pe¡1 aSurur :qr
S-l/il.l:llelS:J lo-: leqlEr uorlll¡ol !
s.tr3Junoc :las !¡ jJ-reJS - Ec jl-rEls : u.r lurod PtEp ¡;rL::
ls+ i:f:rets I (z/Jf ),looTf -s 't g 8lC uI u \1!,t
aceTdel Pue a^To^uo¡ 'ueos 1;i
aSeur Jeut-r-ro :..
1pué iT:ur8Qu l0 :> u¡Uou -l- xlnetlt l..t
ozls Jo
J ur ssnTe^ llns ? l((:)J)LLIns-uuoLl
xef^lc /xpl^tl 01 szrs u6rssec'j I (J) ezrs - IJJ /Jrl
]I T T ] I I (E E)
IIT iI
IIIII
TTIII 8ul1¡rse: tr¡] crl'.::
I I I I t I :J luerue a-,{q - I u : r::.
¡
a.Íenbs aq Jsnul xr,rletr{:rell-!J :i
YrJll?m ,r3tlrl ¡ql
uo pSsPq xutlrri:
xE,l,,lir 'xet\lr oJ azrs ubrsse e,: I (r{) azrs - [I^]3'tilf, sl?u,{\ou{ o.!lf r:
I ot -rTPLI fas != 1I - (llZ/azts),rooTl:Il 'lszrs:Tl)I,,1 'JSee.IJUt 1a:
eo:raz jo xr:rfPl/il I i (aZrs)soraz:U j (azrs)so]3z =t¡ 'lr os 's qtr.\\ p¡t:.
I
xilrJElll 3-renbs Jo ¿zas i !92-azts cq1 e8uur aqr .
dn las xr.trler.il i-.. Sutqloorus arp sr:
¡opura puEllnxotr ! ailedst{,roM or{f s:reeT¡ q: ic , il I lTe -reaTa
6urdaelasnoH:. '6uuollU ?
rellrl oql Jo llnsa, :
p€uorlrsod aq p nc',
:reflrl Terleds aTqeunl '
9I_LZ g JMS .
u|g g I^l :: !: .L
'rallu9x9eqlrMlas elep p 1o 6uua1¡r1 ¡eueds urolod 99 aldutexf
'0 1B J[¿q puP I Jo anle^ e lu JlPtl
qlr,{\ ',{llslle'}ul ut ¡tlds st l¿ql les lr}?p e uo 8ullJE ra11¡ lerleds E S n s,toLl\
g E e¡durexg tq8re,,lr pu¿ uirs lextd lrllU aqt,{q pa¡o.t1uoc sI anle^ [PuU otll o]
lexrd las ulep qcueJo uortnqriluo¡ eql Jellu eql ,{q pere^o. sl luql ios elup otll
Jo s,{¿Jreqns eqt ueá,{\l¡g uortuJlldtllnLu }u:ura¡a-,(q-luaua1a 3I.l1Jo uolll?tllttlns 6-
eql sr uoqPlnslÉJ oqf xllletu ,t\au P uI paJols puP p¡18lnJI€J sI uolleJol 6,,
loxrd eql JoJ anle^ 'reu e'1extd P tlo pJuolltsod sI Jollg áql ,.t,t,'"l.tn_,
oql olul lqanoiq Sutaq st uotluuuojul IPIcUl e 'sotlJ€olddP o,\\] eseql Jo rJtlllé eL-
ul senle^ Iexrd e3p3 3q1 alerrldnp o1 Jo '(SuIppPd olez) solsz qll{\ oáPrul rt{1
(
3o s:8pc cr¡1 puetxa .rerltre ot Jf,ltl¿.Id uouttuoc P sI 1I 'perlsep sl l' [ ) 1¿ SullJels
3-rerl,\\ esec 3rl1 UI los elBp erll Jo lJo rq plnor\ xtJl€tu lellu 3q1 Jo ulunloJ
Duissaioj.J o6eq pue sabeal g )atdeqC
Chapter 5 lmages and lmage
74
matiices with the elements set to zero. Approximately half of the values in the
¿ Tunable spa: _
M matrix are set to 1, creating a sharp transition between the values. This line
?3 House keec _:.:
is sufficiently interesting to look at in detail:
c lear al1; c-:;
M( f1: sizel , [1: ffoor (síZe/2) ] ) :1; 2 set haff to 1
¿* Matrix se-_ _!
The commands in brackets identify regions in the matrix; [1: size] siZe-25;: s r::
r"l - zeros ( st _- ;
identifies rows l through 25' and l1: ¡1oo r \size/2) I identifies the columns
beginning with the first and running through half the size value, 12.5, then
M([1:saze]/ -_:-
rounded downward using the floor O function to 12. The size g function R = size (M) ;
passes the matrix size to two variables that hold the maximum size lrM, cMl : sizs '1.
11111
111111;
lrF/ cFl - size (F) ; ?assign size to rMax, cMax
noRm- sum (F (: ) ) ; % sum values in F
_f n oD,r" -_ 0; noRr _'; e.td,. 15
The script in Example 5.6 includes the conv2 g function approach, and the
results of applying the hlter are shown in Fig. 5.5. The conv2 function g 5l
supports several keyvords that allow the user to tune the way the function is
applied. The keywords include 'full', 'same', and'valid'and change the resulting
shape of the matlix. The 'valid' key,vord returns the convolution without using
zero padding.
The usefulness of spatial filtering becomes apparent when working
directly with images, as the filtering effects can be masked by the viewing
resolution. The effect of many hlters is difficult to show except in electronic
images, where it is possible to zoom in on features of interest. An image- F¡gure 5.6 (left) O
filtering techniq te lhat does have clearly evidelt effects uses sharpening Notice on the right-l
masks, which enhance regions of abrupt change. made to stand out f
'punololceq oql uJorj lno puels ol epeu
pue pa}3alas uaaq seq aoueqc dals aql Jo uor6a.r aql leql a6eu] pueqJqou aql uo actloN
Suru:d.teqs sasn
rallrJ 6uruadreqs oql 6ur^ldde.ieue ebeur aql (lq0u) pue aOeL!r leutorJo (Ual) 9.9 €Jn6tJ
-aSerur uy l s:.i..
sz0zEr0rs 9¿ OZ 51 01 S
rruo-r1la1: ur 1d;:
ñur,ner,r aqt iq I
3nr1:o,u u:q rr I
Sutsn 1noq1r t ut r
3u11¡nser eq1 aiur
sl uonJUnJ ¡qt i:
uorlsulg oz i:_
aqt pue 'qrpo:rl.l:-
aql a.iaq¡ 'slox d ,:
ur s3rl3rlls3r? ,roJ sP IIa,t\ sP Sursseroid PlPp rrlrluorss.roJ pasn oq uec s1J3lJ3 )celq E sr eteql le,:
eql pue'oaelur ue ol perldde Jq uer siolluJo suorluulqtuoj luera.lJrp ,{ueIN
9¿ a¿
'¿ g 31.:l Jo oprs pu¿q-]q8rJ oqt uo u,roqs sr 8ur{sr}ur
d.ieqsun jo sllnsrr 3qt jo a¡durexe uV lrrrurocuuqua aq] apr,lo:d o1 a8eurr
prrr¡19 ueneldel eqt oi peppe sr a8eurr ¡eur8r-ro orll 'ratlu ¡seru dreqsrm
u¿ Jo ulloJ orll uI 0 < V 'sr ]pqt 'pesealcur sr la^e[ tsooq oql puu J8¿uri
uu ol par¡dde sr uorl,lr ueos sq u¿o Je][U SuruedJ€qs srqt
tr Jo sseulnJosn rqJ
'9 9 '3!J
3o epts puuqlq8u rq] uo u,\\oqs tlnsar oql Jcs e,\\'uorlJunJ dals u o1 pcqdde sr
retlu slql uaq¡A 0 - V eieq.u 'g g 3rg 3o cprs pueq-]qiu .la,r\ol sqt ur xutsru 3ur
-ued:eqs oql s€ rr,rorls sr rlcrq,r -'ueroeldp-I oqt sr:al1g Suruad:eqs lsuq y
'a8cuu aql Suruadrcqs
snqt 'pespe,rour eiu aSeulr eql ur s¡ead oql 'aSDLnr leur8uo aqt ot poppe u:q¡A
'a3eutt paqloours arl] e^oq¿ ar1 teqt s¡ead orll ulelqo o1 1r:ur8r"ro eql uol-I
a3r:ur paln¡q erlt lJeJtqns uJql pue cSuur aq1.¡o .{doc e :n1q tslU ol sr sllo.\\
.lJtilJ :rlt ,{p,r arlf a8€ur or-¡} ur s¡eed arueque ol posn sr pue,lset\l d.reqsu¡. 1¡,-= a a .
Jo aluuu lunsnun Jrll spq slatlu Suruedruqs 8urls::a1ur eloul oql Jo JrrO
sTxe ! (.i\a:. .:
.pro¡ Áa)
,prle^, aql 6ursn O ZAuoc 6uruunr jo sllnsou 9'9 arnorj
0agr0rs5z0asr0rE
LL 6ussecoL¿ o6ewl pue sa5eui 9 )eldeqC
Chapter 5
Part
800 800
Figure 5.7 (right) Or¡ginal image and (left) the sharpened image.
Chaptels 6 thror
enhancing images. Being able to construct and apply custom image filtels is a often encounte¡e
powerlul skill and can also be interesting. developing soluti,
visualization tool
5.6 Practice Problems
1. What 3 x 3 flrlter would return the same image that you started with?
2. What is the ellect of the filter 0.5*[0 0 0; 0 I 0; 0 0 0]?
Answers
1.[000; 010;000]
2. It reduces the brightness by half.
References
1. D. Hanselman and B. Littlefield, Masrering MATLAB@ 7, Prentice-Hall,
Upper Saddle River, New Jersey (2011).
2. R. C. Gonzales and R. E. Woods, Digital hnage Processing, Second
Edition, Prentice-Hall, Upper Saddle River, New Jersey (2002).
3. H. Moore, MATLAB@ Jor Engineers, 4th Edition, Prentice-Hall, Upper
Saddle River, New Jersey (2014).
4. R. Pratap, Gexing Started vvitlt MATLAB 7: A Quick Introduction for
Scienrisrs and Engineers, Oxford University Press, Oxford (2006).
Chapter 7
Spectrometers
Spectroscopy can be thought of as working with rainbows, i.e., the separation
of white light into its component colors, which range from red to violet.
Seeing a rainbow, or even better, double rainbows, has great aesthetic value
but is also part of the science behind analyzing light. On the beauty side, cut
glass crystals such as those that might be used in a chandelier will also show
the colors of the rainbow. Refining the shape of these crystals for use in
science has led to new insight in many fields.
The light intensity as a function of wavelength is known as a spectrum and
is used in many analytical systems to determine the composition of materials.
lt is well known that the sun produces a wide range of wavelengths and that
the water vapor in the Earth's atmosphere blocks many wavelengths from
reaching the surface. The areas of the spectrum that can penetrate the
atmosphere are known as atmospheric windows. 1-5 Metallurgy has benefitted
from the use of spectrometers for determining temperatures of highly heated
metals to ensure that the metal processing happens at the right temperatures.
Optical spectrometers can be made usi�g prisms, which rely on refraction
and gratings. Gratings use diffraction to separate out the various wavelengths.
Hybrid devices known as grisms are made from combinations of gratings and
prisms and have the advantage of making very compact instruments.
In this chapter we will model the sorne of the key equations used m
spectrometers and how they relate to the final spectrum.
95
Chapter 11
Polarization
An object viewed through certain crystals will appear as a double image. Such
crystals demonstrate double refraction; i.e., the two directionally dependent
refractive indices through the material result in one image being displaced
from the other. l-4 The explanation of this effect led to our current
understanding of polarization effects.
A wide range of devices incorporate polarization; one of the most
common of these in use today is the liquid crystal display. Liquid crystals were
discovered in the late l 800s and have only recently become the primary
display technology.4 More traditional devices based on polarization include
Pockels cells, Nicol prism, Glan-Thompson prism, and more.3
Polarization, which can be induced by reflection, is found in nature, an
example of which is sunlight glancing off of a body of water. A similar effect
can be created by light interacting with a collection of thin glass plates. It is
important to appreciate that there is a difference between simple reflection
and a polarization effect on reflected light.
Polarization of light is an important topic and often does not receive the
consideration that it should be accorded in many optic courses. Here, we are
interested in the mathematics involved in calculating polarization using
matrix methods. The two formalisms, the Jones calculus and the Mueller
calculus provide an effective means of determining the influence of a polarizer
on a beam of light.
In this chapter we will see how two different yet related matrix approaches
are applied in polarization calculations and how to set up the calculations in
MATLAB®. Interestingly, under certain conditions these two matrix
approaches can be transformed from one to the other.
155