MohamedFathy132015
37 views
25 slides
May 26, 2024
Slide 1 of 25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
About This Presentation
Image Processing
Size: 1.87 MB
Language: en
Added: May 26, 2024
Slides: 25 pages
Slide Content
Computer
Science
1
Digital Image ProcessingSection (4)
A. H. Seddik 2
Assignment #1
Digital Image ProcessingSection (4)
A. H. Seddik 3
Assignment #2
Digital Image ProcessingSection (4)
1-Write a MatLabFunctionthat transposesimage.
Lab Assignments :-
A. H. Seddik 4
2-Write a MatLabFunctionthat Flipsimage Vertically.
3-Write a MatLabFunctionthat Obtains negativeversion of the image.
Digital Image ProcessingSection (4)
Cropping Image
A. H. Seddik 5
Digital Image ProcessingSection (4)
MatLabScripts
A. H. Seddik 6
Code in Command Window
Digital Image ProcessingSection (4)
MatLabFunctions
A. H. Seddik 7
Computer
Science
8
Digital Image Processing
Concept Of Zooming
Section (4)
InthisLecturewearegoingtointroducetheconceptofzooming,andthecommontechniquesthat
areusedtozoomanimage.
Zooming
Zoomingsimplymeansenlargingapictureinasensethatthedetailsintheimagebecamemore
visibleandclear.Zoominganimagehasmanywideapplicationsrangingfromzoomingthrougha
cameralens,tozoomanimageoninternete.t.c.
A. H. Seddik 9
Forexample
Digital Image ProcessingSection (4)
Youcanzoomsomethingattwodifferentsteps:
Thefirststepincludeszoomingbeforetakinganparticularimage.Thisisknownaspreprocessing
zoom.Thiszoominvolveshardwareandmechanicalmovement.
Thesecondstepistozoomonceanimagehasbeencaptured.Itisdonethroughmanydifferent
algorithmsinwhichwemanipulatepixelstozoomintherequiredportion.Wewilldiscussthemin
detailsnext.
OpticalZoomvsdigitalZoom
Thesetwotypesofzoomaresupportedbythecameras.
A. H. Seddik 10
OpticalZoom:
1.Theopticalzoomisachievedusingthemovementofthelensofyourcamera.Anopticalzoomis
actuallyatruezoom.
2.Theresultoftheopticalzoomisfarbetterthenthatofdigitalzoom.Inopticalzoom,an
imageismagnifiedbythelensinsuchawaythattheobjectsintheimageappeartobecloser
tothecamera.
3.Inopticalzoomthelensisphysicallyextendtozoomormagnifyanobject.
Digital Image ProcessingSection (4)
DigitalZoom:
Digitalzoomisbasicallyimageprocessingwithinacamera.Duringadigitalzoom,thecenterofthe
imageismagnifiedandtheedgesofthepicturegotcropout.Duetomagnifiedcenter,itlookslike
thattheobjectisclosertoyou.
Duringadigitalzoom,thepixelsgotexpand,duetowhichthequalityoftheimageiscompromised.
Thesameeffectofdigitalzoomcanbeseenaftertheimageistakenthroughyourcomputerbyusing
animageprocessingtoolbox/software,suchasPhotoshop.
A. H. Seddik 11
Thefollowingpictureistheresultofdigitalzoomdonethrough
oneofthefollowingmethodsgivenbelowinthezooming
methods.
Nowsincewearelearningdigitalimageprocessing,wewillnot
focus,onhowanimagecanbezoomedopticallyusinglensor
otherstuff.Ratherwewillfocusonthemethods,thatenableto
zoomadigitalimage.
Digital Image ProcessingSection (4)
Zoomingmethods:
Althoughtherearemanymethodsthatdoesthisjob,butwearegoingtodiscussthemost
commonofthemhere.
Theyarelistedbelow:
A. H. Seddik 12
1.Pixelreplicationor(Nearestneighborinterpolation)
2.Zeroorderholdmethod
3.ZoomingKtimes
Eachofthemethodshasitsownadvantagesanddisadvantages.Wewillstartbydiscussingpixel
replication.
Digital Image ProcessingSection (4)
Method 1: Pixel replication
Introduction:
A. H. Seddik 13
ItisalsoknownasNearestneighborinterpolation.Asitsnamesuggest,inthismethod,wejust
replicatetheneighboringpixels.Inthismethod,zoomingisnothingbutincreaseamountofpixels.
Thisalgorithmworksonthesameprinciple.
Working:
Inthismethodwecreatenewpixelsformthealreadygivenpixels.Eachpixelisreplicatedinthis
methodntimesrowwiseandcolumnwiseandyougotazoomedimage.Itsassimpleasthat.
Forexample:
ifyouhaveanimageof2rowsand2columnsandyouwanttozoomittwiceor2timesusingpixel
replication,herehowitcanbedone.
Forabetterunderstanding,theimagehasbeentakenintheformofmatrixwiththepixelvaluesof
theimage.
Digital Image ProcessingSection (4)
A. H. Seddik 14
Theaboveimagehastworowsandtwocolumns,wewillfirstzoomitrowwise.
Rowwisezooming:
Whenwezoomitrowwise,wewilljustsimplecopytherowspixelstoitsadjacentnewcell.
Herehowitwouldbedone.
21
43
2211
4433
Asyoucanthatintheabovematrix,eachpixelisreplicatedtwiceintherows.
Digital Image ProcessingSection (4)
A. H. Seddik 15
Columnwisezooming:
Thenextstepistoreplicateeachofthepixelcolumnwise,thatwewillsimplycopythecolumnpixel
toitsadjacentnewcolumnorsimplybelowit.
Herehowitwouldbedone.
2211
4433
2211
2211
4433
4433
Digital Image ProcessingSection (4)
A. H. Seddik 16
Newimagesize
Asitcanbeseenfromtheaboveexample,thatanoriginalimageof2rowsand2columnshasbeen
convertedinto4rowsand4columnsafterzooming.Thatmeansthenewimagehasadimensionsof
(Original image rows * zooming factor, Original Image cols * zooming factor)
Oneoftheadvantageofthiszoomingtechniqueis,itisverysimple.Youjusthavetocopythe
pixelsandnothingelse.
Thedisadvantageofthistechniqueisthatimagegotzoomedbuttheoutputisveryblurry.Andas
thezoomingfactorincreased,theimagegotmoreandmoreblurred.Thatwouldeventually
resultinfullyblurredimage.
Advantageanddisadvantage:
Digital Image ProcessingSection (4)
Method 2: Zero order hold
Introduction:
A. H. Seddik 17
Zeroorderholdmethodisanothermethodofzooming.Itisalsoknownaszoomtwice.Becauseit
canonlyzoomtwice.Wewillseeinthebelowexamplethatwhyitdoesthat.
Working:
Inzeroorderholdmethod,wepicktwoadjacentelementsfromtherowsrespectivelyandthenwe
addthemanddividetheresultbytwo,andplacetheirresultinbetweenthosetwoelements.Wefirst
dothisrowwiseandthenwedothiscolumnwise.
Forexample:
Letstakeanimageofthedimensionsof2rowsand2columnsandzoomittwiceusingzeroorder
hold.
21
43
Firstwewillzoomitrowwiseandthencolumnwise.
Digital Image ProcessingSection (4)
A. H. Seddik 18
Rowwisezooming:
211
433
Aswetakethefirsttwonumbers:(2+1)=3andthenwedivideitby2,weget1.5whichis
approximatedto1.Thesamemethodisappliedintherow2.
Columnwisezooming:
211
322
433
Wetaketwoadjacentcolumnpixelvalueswhichare1and3.Weaddthemandgot4.4isthen
dividedby2andweget2whichisplacedinbetweenthem.Thesamemethodisappliedinallthe
columns.
Digital Image ProcessingSection (4)
A. H. Seddik 19
Newimagesize
Asyoucanseethatthedimensionsofthenewimageare3x3wheretheoriginalimagedimensions
are2x2.Soitmeansthatthedimensionsofthenewimagearebasedonthefollowingformula
(2(number of rows) -1) X (2(number of columns) -1)
Oneoftheadvantageofthiszoomingtechnique,thatitdoesnotcreateasblurrypictureas
comparetothenearestneighborinterpolationmethod.Butitalsohasadisadvantagethatitcanonly
runonthepowerof2.Itcanbedemonstratedhere.
Advantageanddisadvantage:
Considertheaboveimageof2rowsand2columns.Ifwehavetozoomit6times,usingzeroorder
holdmethod,wecannotdoit.Astheformulashowsusthis.Itcouldonlyzoominthepowerof2-
2,4,8,16,32andsoon.
Evenifyoutrytozoomit,youcannot.Becauseatfirstwhenyouwillzoomittwotimes,andtheresult
wouldbesameasshowninthecolumnwisezoomingwithdimensionsequalto3x3.Thenyouwill
zoomitagainandyouwillgetdimensionsequalto5x5.Nowifyouwilldoitagain,youwillget
dimensionsequalto9x9.
Reasonbehindtwicezooming:
Digital Image ProcessingSection (4)
Method 3: K-Times zooming
Introduction:
A. H. Seddik 20
Ktimesisthethirdzoomingmethodwearegoingtodiscuss.Itisoneofthemostperfectzooming
algorithmdiscussedsofar.Itcatersthechallengesofbothtwicezoomingandpixelreplication.Kin
thiszoomingalgorithmstandsforzoomingfactor.
Working:
Itworkslikethisway.
Firstofall,youhavetotaketwoadjacentpixelsasyoudidinthezoomingtwice.Thenyouhaveto
subtractthesmallerfromthegreaterone.Wecallthisoutput(OP).
Dividetheoutput(OP)withthezoomingfactor(K).Nowyouhavetoaddtheresulttothesmallervalue
andputtheresultinbetweenthosetwovalues.
AddthevalueOPagaintothevalueyoujustputandplaceitagainnexttothepreviousputtedvalue.
Youhavetodoittillyouplacek-1valuesinit.
Repeatthesamestepforalltherowsandthecolumns,andyougetazoomedimages.
Digital Image ProcessingSection (4)
For example:
A. H. Seddik 21
Supposeyouhaveanimageof2rowsand3columns,whichisgivenbelow.Andyouhavetozoomit
threetimes.
RowWiseZooming:
Kinthiscaseis3.K=3.
Thenumberofvaluesthatshouldbeinsertedisk-1=3-1=2.
153015
301530
1.Takethefirsttwoadjacentpixels.Whichare15and30.
2.Subtract15from30.30-15=15.
3.Divide15byk.15/k=15/3=5.WecallitOP.(whereopisjustaname)
4.AddOPtolowernumber.15+OP=15+5=20.
5.AddOPto20again.20+OP=20+5=25.
6.Wedothat2timesbecausewehavetoinsertk-1values.
7.Nowrepeatthisstepforthenexttwoadjacentpixels.Itisshowninthefirsttable.
8.Afterinsertingthevalues,youhavetosorttheinsertedvalues,sothereremainsasymmetry
betweenthem.Itisshowninthesecondtable
Digital Image ProcessingSection (4)
Table 1.
A. H. Seddik 22
15252030252015
30252015252030
Table 2.
15202530252015
30252015202530
Digital Image ProcessingSection (4)
Column wise zooming
A. H. Seddik 23
Thesameprocedurehastobeperformedcolumnwise.Theprocedureincludetakingthetwo
adjacentpixelvalues,andthensubtractingthesmallerfromthebiggerone.Thenafterthat,youhave
todivideitbyk.StoretheresultasOP.AddOPtosmallerone,andthenagainaddOPtothevalue
thatcomesinfirstadditionofOP.Insertthenewvalues.
Here what you got after all that.
15202530252015
20212125212120
25222220222225
30252015202530
Digital Image ProcessingSection (4)
A. H. Seddik 24
Newimagesize
Thebestwaytocalculatetheformulaforthedimensionsofanewimageistocomparethe
dimensionsoftheoriginalimageandthefinalimage.Thedimensionsoftheoriginalimagewere2X
3.Andthedimensionsofthenewimageare4x7.Theformulathusis:
(K (number of rows -1) + 1) X (K (number of cols -1) + 1)
Theoneoftheclearadvantagethatktimezoomingalgorithmhasthatitisabletocomputezoomof
anyfactorwhichwasthepowerofpixelreplicationalgorithm,alsoitgivesimprovedresult(less
blurry)whichwasthepowerofzeroorderholdmethod.SohenceItcomprisesthepowerofthe
twoalgorithms.
Theonlydifficultythisalgorithmhasthatithastobesortintheend,whichisanadditional
step,andthusincreasesthecostofcomputation.
Advantageanddisadvantage: