assignment 5

Post on 06-Sep-2015

213 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Several methods for Gradient and Edge Detection

TRANSCRIPT

  • Hai Dang CS6475 - SPRING 2015 ASSIGNMENT 5

    GRADIENT AND EDGE DETECTION I. CalculateGradientinXandinYdirection:

    Thisisrathersimple,Ijustiteratethrougheverypixel,andsetittothedifferenceofthepixelinthenextcolumn/nextrow.Belowisthecode.AlsoImadesuretoassigntheboundaryvaluestozeros.

    defimageGradientX(image):ret=np.copy(image)

    foriinrange(0,ret.shape[0]): forjinrange(0,ret.shape[1]1): ret[i][j]=abs(int(ret[i][j+1])int(ret[i][j])) ret[i][ret.shape[1]1]=0

    returnretdefimageGradientY(image):

    ret=np.copy(image)foriinrange(0,image.shape[0]1):

    forjinrange(0,image.shape[1]): ret[i][j]=abs(int(ret[i+1][j])int(ret[i][j]))

    forjinrange(0,image.shape[1]): ret[image.shape[0]1][j]=0

    returnretII. CalculateCorrelationbyapplyingakerneltothepicture:

    Thisisalsostraightforward.Ijustiteratethrougheverypixel,andforeachpixel,applytheformulafromthelecture.BelowisthecodedefcomputeGradient(image,kernel):

    ret=np.copy(image)forjinrange(0,image.shape[1]):

    ret[0][j]=0 ret[image.shape[0]1][j]=0

    foriinrange(0,image.shape[0]):

  • ret[i][0]=0 ret[i][image.shape[1]1]=0

    foriinrange(1,image.shape[0]1): forjinrange(1,image.shape[1]1): val=0 foruinrange(0,3): forvinrange(0,3): val=val+kernel[u][v]*image[i+u1][j+v1] ret[i][j]=int(val)

    returnretIII. EdgeDetection:

    1. OriginalPicture:

  • 2.Methods:ItriedseveralmethodsotherthanCannysEdgeDetector,andhavefoundtwowaystodeliverdecentresults.

    A. Method1:a. CalculateGradientinXandinYdirectionb. Foreachpixel,getthemaxofthevalues.Theresultisshownbelow

    c. Now,toshowtheedgesinthepicture,Iusethekernelofsize3x3tosmoothoutthenoisefirst,thenchoosethethresholdtobetheaverageofallthepixel.I

    d. Iteratethroughallpixel,assignitto255ifitsvalueisgreaterthan3timestheaverage,and0otherwise.Belowisthepicture

  • B.Method2:

    a. CalculateGradientinXandinYdirection(Similartomethod1)b. Foreachpixel,getthemaxofthevalues.(Similartomethod1)c. Now,toshowtheedgesinthepicture,Iusethekernelofsize3x3tosmoothoutthe

    noisefirst,thenchoosethethresholdtobetheaverageofallthepixel.Id. Now,treattheproblemofedgedetectorasanomalydetection.Wewillusearolling

    windows(Ipickedthesize30x30)tomoveacrossthepicture.e. Calculatemeanandstandarddeviationofallvaluesfromthatwindows.Anypixelwith

    valuegreaterthanmean+stdisconsideredasanomaly,andhencechangethevalueto255.Otherwise,weassign0toothers.Belowistheresult

  • 3.CannyEdgeDetectionForcomparisonpurposes,IhaveattachedtheresultofCannysEdgeDetectionbelowtoshowthedifferences.

  • 4.FurtherDevelopment:Asonecansee,mymethodsdonthavetheresultasgoodasCannysEdgeDetectionyet.Howevertheyhavealotofpotentialandcanbeimprove.Wecanchangethesizeofthekerneltoimprovesmoothing,wecanalsofinetunethethresholdtogetbetterresults.ThebestimprovementIbelieveistocombinemultiplemethodtogether,andhavesomevotingmechanismtotellwhetherapixelshouldbelongtoanedgeornot.

top related