斯坦福机器视觉_第1页
斯坦福机器视觉_第2页
斯坦福机器视觉_第3页
斯坦福机器视觉_第4页
斯坦福机器视觉_第5页
已阅读5页,还剩72页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

LinearAlgebraPrimerProfessorFei-FeiLiStanfordVisionLab22-Apr-231Another,veryin-depthlinearalgebrareviewfromCS229isavailablehere:http://AndavideodiscussionoflinearalgebrafromEE263ishere(lectures3and4):http://OutlineVectorsandmatricesBasicMatrixOperationsSpecialMatricesTransformationMatricesHomogeneouscoordinatesTranslationMatrixinverseMatrixrankSingularValueDecomposition(SVD)UseforimagecompressionUseforPrincipalComponentAnalysis(PCA)Computeralgorithm22-Apr-232OutlineVectorsandmatricesBasicMatrixOperationsSpecialMatricesTransformationMatricesHomogeneouscoordinatesTranslationMatrixinverseMatrixrankSingularValueDecomposition(SVD)UseforimagecompressionUseforPrincipalComponentAnalysis(PCA)Computeralgorithm22-Apr-233Vectorsandmatricesarejustcollectionsoforderednumbersthatrepresentsomething:movementsinspace,scalingfactors,pixelbrightnesses,etc.We’lldefinesomecommonusesandstandardoperationsonthem.VectorAcolumnvectorwhereArowvectorwheredenotesthetransposeoperation22-Apr-234VectorWe’lldefaulttocolumnvectorsinthisclassYou’llwanttokeeptrackoftheorientationofyourvectorswhenprogramminginMATLABYoucantransposeavectorVinMATLABbywritingV’.(Butinclassmaterials,wewillalwaysuseVTtoindicatetranspose,andwewilluseV’tomean“Vprime”)22-Apr-235VectorshavetwomainusesVectorscanrepresentanoffsetin2Dor3DspacePointsarejustvectorsfromtheorigin22-Apr-236Data(pixels,gradientsatanimagekeypoint,etc)canalsobetreatedasavectorSuchvectorsdon’thaveageometricinterpretation,butcalculationslike“distance”canstillhavevalueMatrix

22-Apr-237Images22-Apr-238MATLABrepresentsanimageasamatrixofpixelbrightnessesNotethatmatrixcoordinatesareNOTCartesiancoordinates.Theupperleftcorneris[y,x]=(1,1)=ColorImagesGrayscaleimageshaveonenumberperpixel,andarestoredasanm×nmatrix.Colorimageshave3numbersperpixel–red,green,andbluebrightnessesStoredasanm×n×3matrix22-Apr-239=BasicMatrixOperationsWewilldiscuss:AdditionScalingDotproductMultiplicationTransposeInverse/pseudoinverseDeterminant/trace22-Apr-2310MatrixOperationsAdditionCanonlyaddamatrixwithmatchingdimensions,orascalar.Scaling22-Apr-2311MatrixOperationsInnerproduct(dotproduct)ofvectorsMultiplycorrespondingentriesoftwovectorsandadduptheresultx·yisalso|x||y|Cos(theanglebetweenxandy)22-Apr-2312MatrixOperationsInnerproduct(dotproduct)ofvectorsIfBisaunitvector,thenA·BgivesthelengthofAwhichliesinthedirectionofB22-Apr-2313MatrixOperationsMultiplicationTheproductABis:Eachentryintheresultis(thatrowofA)dotproductwith(thatcolumnofB)Manyuses,whichwillbecoveredlater22-Apr-2314MatrixOperationsMultiplicationexample:22-Apr-2315Eachentryofthematrixproductismadebytakingthedotproductofthecorrespondingrowintheleftmatrix,withthecorrespondingcolumnintherightone.MatrixOperationsPowersByconvention,wecanrefertothematrixproductAAasA2,andAAAasA3,etc.Obviouslyonlysquarematricescanbemultipliedthatway22-Apr-2316MatrixOperationsTranspose–flipmatrix,sorow1becomescolumn1Ausefulidentity:22-Apr-2317DeterminantreturnsascalarRepresentsarea(orvolume)oftheparallelogramdescribedbythevectorsintherowsofthematrixFor,Properties:22-Apr-2318MatrixOperationsTraceInvarianttoalotoftransformations,soit’susedsometimesinproofs.(Rarelyinthisclassthough.)Properties:22-Apr-2319MatrixOperationsSpecialMatricesIdentitymatrixISquarematrix,1’salongdiagonal,0’selsewhereI

[anothermatrix]=[thatmatrix]DiagonalmatrixSquarematrixwithnumbersalongdiagonal,0’selsewhereAdiagonal∙

[anothermatrix]scalestherowsofthatmatrix22-Apr-2320SpecialMatricesSymmetricmatrixSkew-symmetricmatrix22-Apr-2321OutlineVectorsandmatricesBasicMatrixOperationsSpecialMatricesTransformationMatricesHomogeneouscoordinatesTranslationMatrixinverseMatrixrankSingularValueDecomposition(SVD)UseforimagecompressionUseforPrincipalComponentAnalysis(PCA)Computeralgorithm22-Apr-2322Matrixmultiplicationcanbeusedtotransformvectors.Amatrixusedinthiswayiscalledatransformationmatrix.TransformationMatricescanbeusedtotransformvectorsinusefulways,throughmultiplication:x’=AxSimplestisscaling:(Verifytoyourselfthatthematrixmultiplicationworksoutthisway)22-Apr-2323RotationHowcanyouconvertavectorrepresentedinframe“0”toanew,rotatedcoordinateframe“1”?Rememberwhatavectoris:[componentindirectionoftheframe’sxaxis,componentindirectionofyaxis]22-Apr-2324RotationSotorotateitwemustproducethisvector:[componentindirectionofnewxaxis,componentindirectionofnewyaxis]Wecandothiseasilywithdotproducts!Newxcoordinateis[originalvector]dot[thenewxaxis]Newycoordinateis[originalvector]dot[thenewyaxis]22-Apr-2325RotationInsight:thisiswhathappensinamatrix*vectormultiplicationResultxcoordinateis[originalvector]dot

[matrixrow1]Somatrixmultiplicationcanrotateavectorp:22-Apr-2326RotationSupposeweexpressapointinacoordinatesystemwhichisrotatedleftIfweusetheresultinthesamecoordinatesystem,wehaverotatedthepointright22-Apr-2327Thus,rotationmatricescanbeusedtorotatevectors.We’llusuallythinkoftheminthatsense--asoperatorstorotatevectors2DRotationMatrixFormulaCounter-clockwiserotationbyananglePxy’P’x’y22-Apr-2328TransformationMatricesMultipletransformationmatricescanbeusedtotransformapoint:

p’=R2R1SpTheeffectofthisistoapplytheirtransformationsoneaftertheother,fromrighttoleft.Intheexampleabove,theresultis

(R2(R1(Sp)))Theresultisexactlythesameifwemultiplythematricesfirst,toformasingletransformationmatrix:

p’=(R2R1S)p22-Apr-2329HomogeneoussystemIngeneral,amatrixmultiplicationletsuslinearlycombinecomponentsofavectorThisissufficientforscale,rotate,skewtransformations.Butnotice,wecan’taddaconstant!22-Apr-2330HomogeneoussystemThe(somewhathacky)solution?Sticka“1”attheendofeveryvector:Nowwecanrotate,scale,andskewlikebefore,ANDtranslate(notehowthemultiplicationworksout,above)Thisiscalled“homogeneouscoordinates”22-Apr-2331HomogeneoussystemInhomogeneouscoordinates,themultiplicationworksoutsotherightmostcolumnofthematrixisavectorthatgetsadded.Generally,ahomogeneoustransformationmatrixwillhaveabottomrowof[001],sothattheresulthasa“1”atthebottomtoo.22-Apr-2332HomogeneoussystemOnemorethingwemightwant:todividetheresultbysomethingForexample,wemaywanttodividebyacoordinate,tomakethingsscaledownastheygetfartherawayinacameraimageMatrixmultiplicationcan’tactuallydivideSo,byconvention,inhomogeneouscoordinates,we’lldividetheresultbyitslastcoordinateafterdoingamatrixmultiplication22-Apr-23332DTranslationtPP’22-Apr-233422-Apr-23352DTranslationusingHomogeneousCoordinatesPxytxtyP’ttPScalingPP’22-Apr-2336ScalingEquationPxysxxP’sy

y22-Apr-2337PP’=S∙PP’’=T∙P’P’’=T∙P’=T∙(S∙P)=T∙S∙P=A∙

PScaling&TranslatingP’’22-Apr-2338Scaling&TranslatingA22-Apr-2339Translating&Scaling

!=Scaling&Translating22-Apr-2340RotationPP’22-Apr-2341RotationEquationsCounter-clockwiserotationbyananglePxy’P’x’y22-Apr-2342RotationMatrixPropertiesTransposeofarotationmatrixproducesarotationintheoppositedirectionTherowsofarotationmatrixarealwaysmutuallyperpendicular(a.k.a.orthogonal)unitvectors(andsoareitscolumns)22-Apr-2343PropertiesA2Drotationmatrixis2x2Note:Rbelongstothecategoryofnormalmatricesandsatisfiesmanyinterestingproperties:22-Apr-2344Rotation+Scaling+TranslationP’=(TRS)P22-Apr-2345Thisistheformofthegeneral-purposetransformationmatrixOutlineVectorsandmatricesBasicMatrixOperationsSpecialMatricesTransformationMatricesHomogeneouscoordinatesTranslationMatrixinverseMatrixrankSingularValueDecomposition(SVD)UseforimagecompressionUseforPrincipalComponentAnalysis(PCA)Computeralgorithm22-Apr-2346TheinverseofatransformationmatrixreversesitseffectGivenamatrixA,itsinverseA-1

isamatrixsuchthatAA-1=A-1A=IE.g.Inversedoesnotalwaysexist.IfA-1exists,Aisinvertibleornon-singular.Otherwise,it’ssingular.Usefulidentities,formatricesthatareinvertible:22-Apr-2347InversePseudoinverseSayyouhavethematrixequationAX=B,whereAandBareknown,andyouwanttosolveforXYoucoulduseMATLABtocalculatetheinverseandpremultiplybyit:A-1AX=A-1B→X=A-1BMATLABcommandwouldbeinv(A)*BButcalculatingtheinverseforlargematricesoftenbringsproblemswithcomputerfloating-pointresolution(becauseitinvolvesworkingwithverysmallandverylargenumberstogether).Or,yourmatrixmightnotevenhaveaninverse.22-Apr-2348MatrixOperationsPseudoinverseFortunately,thereareworkaroundstosolveAX=Binthesesituations.AndMATLABcandothem!Insteadoftakinganinverse,directlyaskMATLABtosolveforXinAX=B,bytypingA\BMATLABwilltryseveralappropriatenumericalmethods(includingthepseudoinverseiftheinversedoesn’texist)MATLABwillreturnthevalueofXwhichsolvestheequationIfthereisnoexactsolution,itwillreturntheclosestoneIftherearemanysolutions,itwillreturnthesmallestone22-Apr-2349MatrixOperationsMATLABexample:22-Apr-2350MatrixOperations>>x=A\Bx=1.0000-0.5000OutlineVectorsandmatricesBasicMatrixOperationsSpecialMatricesTransformationMatricesHomogeneouscoordinatesTranslationMatrixinverseMatrixrankSingularValueDecomposition(SVD)UseforimagecompressionUseforPrincipalComponentAnalysis(PCA)Computeralgorithm22-Apr-2351Therankofatransformationmatrixtellsyouhowmanydimensionsittransformsavectorto.LinearindependenceSupposewehaveasetofvectorsv1,…,vnIfwecanexpressv1asalinearcombinationoftheothervectorsv2…vn,thenv1islinearlydependentontheothervectors.Thedirectionv1canbeexpressedasacombinationofthedirectionsv2…vn.(E.g.v1=.7

v2-.7

v4)Ifnovectorislinearlydependentontherestoftheset,thesetislinearlyindependent.Commoncase:asetofvectorsv1,…,vnisalwayslinearlyindependentifeachvectorisperpendiculartoeveryothervector(andnon-zero)22-Apr-2352LinearindependenceNotlinearlyindependent22-Apr-2353LinearlyindependentsetMatrixrankColumn/rowrankColumnrankalwaysequalsrowrankMatrixrank22-Apr-2354MatrixrankFortransformationmatrices,theranktellsyouthedimensionsoftheoutputE.g.ifrankofAis1,thenthetransformation

p’=Ap

mapspointsontoaline.Here’samatrixwithrank1:22-Apr-2355Allpointsgetmappedtotheliney=2xMatrixrankIfanmxmmatrixisrankm,wesayit’s“fullrank”Mapsanmx1vectoruniquelytoanothermx1vectorAninversematrixcanbefoundIfrank<m,wesayit’s“singular”Atleastonedimensionisgettingcollapsed.NowaytolookattheresultandtellwhattheinputwasInversedoesnotexistInversealsodoesn’texistfornon-squarematrices22-Apr-2356OutlineVectorsandmatricesBasicMatrixOperationsSpecialMatricesTransformationMatricesHomogeneouscoordinatesTranslationMatrixinverseMatrixrankSingularValueDecomposition(SVD)UseforimagecompressionUseforPrincipalComponentAnalysis(PCA)Computeralgorithm22-Apr-2357SVDisanalgorithmthatrepresentsanymatrixastheproductof3matrices.Itisusedtodiscoverinterestingstructureinamatrix.SingularValueDecomposition(SVD)Thereareseveralcomputeralgorithmsthatcan“factor”amatrix,representingitastheproductofsomeothermatricesThemostusefuloftheseistheSingularValueDecomposition.RepresentsanymatrixAasaproductofthreematrices:UΣVTMATLABcommand:[U,S,V]=svd(A)22-Apr-2358SingularValueDecomposition(SVD)

UΣVT=AWhereUandVarerotationmatrices,andΣisascalingmatrix.Forexample:22-Apr-2359SingularValueDecomposition(SVD)Beyond2D:Ingeneral,ifAismxn,thenUwillbemxm,Σwillbemxn,andVTwillbenxn.(Notethedimensionsworkouttoproducemxnaftermultiplication)22-Apr-2360SingularValueDecomposition(SVD)UandVarealwaysrotationmatrices.Geometricrotationmaynotbeanapplicableconcept,dependingonthematrix.Sowecallthem“unitary”matrices–eachcolumnisaunitvector.ΣisadiagonalmatrixThenumberofnonzeroentries=rankofAThealgorithmalwayssortstheentrieshightolow22-Apr-2361SVD

ApplicationsWe’vediscussedSVDintermsofgeometrictransformationmatricesButSVDofanimagematrixcanalsobeveryusefulTounderstandthis,we’lllookatalessgeometricinterpretationofwhatSVDisdoing22-Apr-2362SVD

ApplicationsLookathowthemultiplicationworksout,lefttoright:Column1ofUgetsscaledbythefirstvaluefromΣ.Theresultingvectorgetsscaledbyrow1ofVTtoproduceacontributiontothecolumnsofA22-Apr-2363SVD

ApplicationsEachproductof(columniofU)∙(valueifromΣ)∙(rowiofVT)producesacomponentofthefinalA.22-Apr-2364+=SVD

ApplicationsWe’rebuildingAasalinearcombinationofthecolumnsof

UUsingallcolumnsofU,we’llrebuildtheoriginalmatrixperfectlyBut,inreal-worlddata,oftenwecanjustusethefirstfewcolumnsofUandwe’llgetsomethingclose(e.g.thefirstApartial,above)22-Apr-2365SVD

ApplicationsWecancallthosefirstfewcolumnsof

UthePrincipalComponentsofthedataTheyshowthemajorpatternsthatcanbeaddedtoproducethecolumnsoftheoriginalmatrixTherowsofVTshowhowtheprincipalcomponentsaremixedtoproducethecolumnsofthematrix22-Apr-2366SVD

ApplicationsWecanlookatΣtoseethatthefirstcolumnhasalargeeffect22-Apr-2367whilethesecondcolumnhasamuchsmallereffectinthisexampleSVD

Applications22-Apr-2368Forthisimage,usingonlythefirst10of300principalcomponentsproducesarecognizablereconstructionSo,SVDcanbeusedforimagecompressionPrincipalComponentAnalysisRemember,columnsof

UarethePrincipalComponentsofthedata:themajorpatternsthatcanbeaddedtoproducethecolumnsoftheoriginalmatrixOneuseofthisistoconstructamatrixwhereeachcolumnisaseparatedatasampleRunSVDonthatmatrix,andlookatthefirstfewcolumnsofUtoseepatternsthatarecommonamongthecolumnsThisiscalledPrincipalComponentAnalysis(orPCA)ofthedatasamples22-Apr-2369PrincipalComponentAnalysisOften,rawdatasampleshavealotofredundancyandpatternsPCAcanallowyoutorepresentdatasamplesasweightsontheprincipalcomponents,ratherthanusingtheoriginalrawformofthedataByrepresentingeachsampleasjustthoseweights,youcanrepresentjustthe“meat”ofwhat’sdifferentbetweensamples.Thisminimalrepresentationmakesmachinelearningandotheralgorithmsmuchmoreefficient22-Apr-2370OutlineVectorsandmatricesBasicMatrixOperationsSpecialMatricesTransformationMatricesHomogeneouscoordinatesTranslationMatrixinverseMatrixrankSingularValueDecomposition(SVD)UseforimagecompressionUseforPrincipalComponentAnalysis(PCA)Computeralgorithm22-Apr-2371ComputerscancomputeSVDveryquickly.We’llbrieflydiscussthealgorithm,forthosewhoareinterested.Addendum:HowisSVDcomputed?Forthisclass:tellMATLABtodoit.Usetheresult.But,ifyou’reinterested,onecomputeralgorithmtodoitmakesuseofEigenvectorsThefollowingmaterialispresentedtomakeSVDlessofa“magicalblackbox.”ButyouwilldofineinthisclassifyoutreatSVDasamagicalblackbox,aslongasy

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论