数字图像处理作业.docx
《数字图像处理作业.docx》由会员分享,可在线阅读,更多相关《数字图像处理作业.docx(18页珍藏版)》请在冰豆网上搜索。
数字图像处理作业
数字图像处理实验报告
学号:
16S051049
姓名:
代烁
专业:
计算机科学与技术
日期:
2017.4.15
1Introduction1
2HistogramEqualization1
2.1CentralIdeas1
2.2ApplicationScenario1
2.3CumulativeDistributionFunction1
2.4AdvantagesandDisadvantages2
2.5Algorithm2
2.6Theresults3
3NoiseReduction5
3.1TypeofthisNoise5
3.2MedianFilter5
3.2.1MainIdea5
3.2.2ApplicationScenario6
3.2.3Algorithm6
3.2.4Theresults6
3.3AveragingFilter8
3.3.1Introduction8
3.3.2Algorithm8
3.3.3Theresults9
4Gaussianhighpassfilters10
4.1Introduction10
4.2Algorithm11
4.3Theresults11
5Conclusion15
1Introduction
Inthisprojectwemainlysolvethreeproblemsaboutimageenhancement.Thefirstquestionishistogramequalization,thesecondquestionisnoisereduction,andthethirdquestionisGaussianhighpassfilters.Isolvethethreequestionbyusingpythonprogramminglanguage.
2HistogramEqualization
2.1CentralIdeas
Thehistogramisbasedonthestatisticsofthegreylevelsofpixels.Histogramequalizationisamethodofadjustingthecontrastusingimagehistogramsinthefieldofimageprocessing.Histogramequalizationisdonebyusingthecumulativedistributionfunctiontoadjustthegrayvaluetoachievethepurposeofcontrastenhancement.Thecentralideaofhistogramequalizationistochangethegrayhistogramoftheoriginalimagefromarelativelyconcentratedgrayscaletoauniformdistributionovertheentiregrayscale,whichincreasesthedynamicrangeofthepixelgrayscalevaluesoastoachievetheeffectofenhancingtheoverallcontrastoftheimage.Histogramequalizationisthenon-linearstretchingoftheimage,redistributeofimagepixelvalues,tomakethenumberofpixelsinacertaingrayscalerangeapproximatelythesame.Histogramequalizationistochangethehistogramdistributionofagivenimagetoauniformdistributionhistogramdistribution.
2.2ApplicationScenario
Thismethodisoftenusedtoincreasethelocalcontrastofmanyimages,especiallywhenthecontrastoftheusefuldataoftheimageisfairlyclose.Inthisway,thebrightnesscanbebetterdistributedoverthehistogram.Thiscanbeusedtoenhancethelocalcontrastwithoutaffectingtheoverallcontrast,histogramequalizationbyeffectivelyexpandingthecommonlyusedbrightnesstoachievethisfunction.Thismethodisveryusefulforbackgroundsandprospectsthataretoobrightortoodark,forexample,skeletalstructuresinX-rayimages,overexposureorunderexposurephotos.
2.3CumulativeDistributionFunction
Equalizationprocess,wemustensurethatthetwoconditions:
nomatterhowthepixelmap,wemustensurethatthegraysizerelationshipoforiginalimagekeepunchanged,thebrightareaisstillbrighter,darkstilldark,butthecontrastincreases.
Ifitisaneight-bitimage,thenthevalueofthepixelmappingfunctionshouldbebetween0and255,donotcrosstheborder.
Basedontheabovetwoconditions,thecumulativedistributionfunctionisagoodchoice,becausethecumulativedistributionfunctionisamonotonicallyincreasingfunction(Toensurethattheenhancedprocessingdoesnotdisruptthegrayscaleorderoftheoriginalimage),andtherangeis0to1.
2.4AdvantagesandDisadvantages
Advantages
Itisafairlyintuitivetechniqueandisareversibleoperation.Iftheequalizationfunctionisknown,thentheoriginalhistogramcanberestoredandtheamountofcomputationisnotlarge.
Disadvantages
1.Thegrayscaleofthetransformedimageisreducedandsomedetailsdisappear
2.Someimages,ifthehistogramhaveapeak,aftertreatment,thecontrastisunnatural.
3.Itdoesnotselectthedatatobeprocessed,itmayincreasethecontrastofthebackgroundandreducethecontrastoftheusefulsignal
2.5Algorithm
Thehistogramequalizationalgorithmisdividedintothreesteps.
1.Countthenumberofpixelsineachappearinggraylevel.Thenmap(graylevel,thenumberofpixelsofthisgraylevel).
2.Sortbythegraylevel
3.Foreverygraylevel,Sumallthenumberofpixelsofgraylevelbeforeitincludingthenumberofpixelsofit.Thenmap(graylevel,sumthenumberofpixelsstilltocurrentgraylevel)
4.Foreverygraylevel,normalize“sumthenumberofpixelsstilltocurrentgraylevel”
5.everynormalizedresult*255
2.6Theresults
Figure1thehistogramoforiginalimage
Figure2histogramafterhistogramequalization
Figure3originalimage
Figure4imageafterhistogramequalization
Wegettheuniformdistributionhistogramovertheentiregrayscale,comparedtothegrayhistogramoftheoriginalimagefromarelativelyconcentratedgrayscale.Weachievetheeffectofenhancingtheoverallcontrastoftheimage.
3NoiseReduction
3.1TypeofthisNoise
Figure5imageb
Wewillremovethenoisefromtheimageb.Filteringisoftenusedtoremovenoisefromimages.Wecanknowthenoiseinimagebissaltandpepper.Salt-and-peppernoisealsocalledimpulsenoise,itpresentsitselfassparselyoccurringwhiteandblackpixels.Salt-and-peppernoiseisproducedbytheimagesensor,transmissionchannel,decodingprocessing.Aswecanthoseblackorwhitepointsareverydifferentfromthepixelsaroundit,soweregardthemasexceptionvalue.Sowecanreplaceexceptionvaluewithpixelsaroundit.Aneffectivenoisereductionmethodforthistypeofnoiseisamedianfilter.Inaddition,wetrytheeffectofaveragingfilter.
3.2MedianFilter
3.2.1MainIdea
Medianfilterisanonlineardigitalfilteringtechnique.Thebasicprincipleofmedianfilteristhatwereplacethevalueofapointinthedigitalimageorasequenceofdigitwiththemedianofeachpointinneighborsofthepointinordertoeliminateisolatednoisepoints.Themethodistousetwo-dimensionalslidingtemplate,thetemplateiscalledthe“window”.Ifthewindowhasanoddnumberofpoints,itisjustthemiddlevalueafterallthepixelsinthewindowaresortednumerically.
3.2.2ApplicationScenario
Medianfilterisparticularlyeffectiveinthepresenceofsalt-and-peppernoise
3.2.3Algorithm
edge=step/2
foriinrange(edge,imageheight-edge)
forjinrange(edge,imagewidth-edge)
sum=[]
forkinrange(-edge,edge+1):
forminrange(-edge,edge+1):
sum.append(image[i+k][j+m])
sum.sort()
image[i][j]=sum[int(step*step/2)+1]
3.2.4Theresults
Figure6
medianfilter
Figure7
medianfilter
Figure8
medianfilter
WecanseefromtheFigure6-8thatmedianfilterisparticularlyeffectiveinthepresenceofsalt-and-peppernoiseandthelargerthesizeofthewindow,themoreblurrytheimagebecomes.Wecanfindthatmedianfiltercan’tfiltertheedgenoise.
3.3AveragingFilter
3.3.1Introduction
Averagingfilterisatypicallinearfilteringalgorithm.Itsprincipleisthatreplacetheoriginalpixelvaluewiththeaveragepixelofallpixelsaroundit.Averagingfilterdestroysthedetailsoftheimagewhilereducenoiseoftheimage,sothattheimagebecomesblurredandthenoiseisnotwellremoved.ForGaussiannoise,theeffectofthemeanfilteringisbetterthanthatofthemedianfilter.
3.3.2Algorithm
edge=step/2
foriinrange(edge,imageheight-edge)
forjinrange(edge,imagewidth-edge)
sum=[]
forkinrange(-edge,edge+1):
forminrange(-edge,edge+1):
sum.append(image[i+k][j+m])
image[i][j]=sum.sum/(step*step)
3.3.3Theresults
Figure9
averagingfilter
WecanseefromtheFigure9thattheimageisveryblurry.Forsalt-and-peppernoise,themedianfilterisbetterthanaveragingfilter.
4Gaussianhighpassfilters
4.1Introduction
Figure10imagec
AGaussianfilterisaclassoflinearsmoothingfiltersthatselectweightsbasedontheshapeoftheGaussianfunction.TheGaussiansmoothingfilterisveryeffectiveinsuppressingnoisefromthenormaldistribution.GaussianSharpencanmakeimagelookclearerbymodifyingthedifferencebetweenthelightanddarkpoints,andcanproducemoreobviouscontrastbetweenbrightanddarkpixels.InFouriertransform,thelowfrequenciesareresponsibleforthegeneralgreylevelappearanceofanimageoversmoothareas.Thehigherfrequenciesbegintocorrespondtofasterandfastergraylevelchangesintheimage.Highpassfiltersonlypassthehighfrequencies,dropthelowones.Detailssuchasedgesandnoisesinimagesareassociatedwithhighfrequencycomponents,sowecangetedgesandfinedetailinformationbyhighpassfilters.Wewillenhancetheimageinthefrequencydomain,firstlywewillgetthediscreteFouriertransformoftheimage.
ThetransferfunctionofaGaussianhighpassfilterisdefinedas:
isthecut-offfrequency,
isthesquareofthedistancefromthepointintheimagetothecenterpoint.
4.2Algorithm
1.ThefastFouriertransformalgorithmisusedtoobtainthefrequencydistribution
2.Thedefaultresultcenterpointpositionisintheupperleftcorner,moveittothemiddleposition,getfshift
3.Getthewidthandheightofthisimage
4.MakethecutoffdistanceD0equal15,30,80
5.Getcenterpointcoordinate(m,n)ofthisimage
6.Traverseeachpointcoordinate(i,j)intheimage
7.d=thesquareof(i-m)+thesquare(n-j)
8.h=exp(-d/(2*thesquareofD0))
9.Result[i][j]=(1-h)*fshift[i][j]
10.Thenbacktothespatialdomaintorestoretheimage
4.3Theresults
Figure11Fourierspectrumoftheimagec
Figure12ResultsofGaussianhighpassfilteringwithD0=15
Figure13FourierspectrumofimageofGaussianhighpassfilteringwithD0=15
Figure14ResultsofGaussianhighpassfilteringwithD0=30
Figure15FourierspectrumofimageofGaussianhighpassfilteringwithD0=30
Figure16ResultsofGaussianhighpassfilteringwithD0=80
Figure17Fourierspect