{VERSION 3 0 "APPLE_PPC_MAC" "3.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 }{PSTYLE " Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 0 0 0 0 0 1 3 0 3 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Heading 1" 0 3 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 0 0 0 0 0 0 0 }1 0 0 0 8 4 0 0 0 0 0 0 -1 0 }{PSTYLE "Heading \+ 2" 3 4 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 8 2 0 0 0 0 0 0 -1 0 }{PSTYLE "Heading 3" 4 5 1 {CSTYLE "" -1 -1 "" 1 12 0 0 0 0 1 0 0 0 0 0 0 0 0 }0 0 0 -1 0 0 0 0 0 0 0 0 -1 0 }{PSTYLE " Warning" 2 7 1 {CSTYLE "" -1 -1 "" 0 1 0 0 255 1 0 0 0 0 0 0 1 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Output" 0 11 1 {CSTYLE " " -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 11 12 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Plot" 0 13 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {SECT 0 {PARA 3 "" 0 "" {TEXT -1 12 "Introduction" }}{PARA 0 " " 0 "" {TEXT -1 312 "This worksheet demonstrates some of the key conce pts associated with recognizing images based upon nearest neighbor com parisons in the Eigenspace associated with a set of training images. \+ This has been prepared to go with CS510 and the text \"Introductory Te chniques for 3-D Computer Vision\" by Trucco and Verri." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 126 "A series of these w orksheets have been made available showing slightly different test cas es. This is the first in the series. " }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 43 "Ross Beveridge April 23 , 1999" }}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 15 "Initializations" }} {PARA 0 "" 0 "" {TEXT -1 20 "Libraires used here." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "with(linalg):\nwith(stats):\nwith(plots):" } {TEXT -1 1 "\n" }}{PARA 7 "" 1 "" {TEXT -1 32 "Warning, new definition for norm" }}{PARA 7 "" 1 "" {TEXT -1 33 "Warning, new definition for \+ trace" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 240 "Here are some global va riables used to adjust how this worksheet behaves. It is thus possibl e to change the size of the test images, the low and high values in th ese images, the number of instances of each class in the training data , etc. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 269 "imageSize := 3; # The row and column dimension of the images\nimageLow := \+ 2.0; # The low value in the test imagery\nimageHigh := 7.0; # T he high value in the test imagery\ntrainingSize := 9; # The number of training images. Should be a multiple of 3." }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%*imageSizeG\"\"$" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#> %)imageLowG$\"#?!\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%*imageHighG $\"#q!\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%-trainingSizeG\"\"*" } }}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 23 "Some Library Procedures" }} {PARA 0 "" 0 "" {TEXT -1 238 "The followling procedures are helpful fo r working viewing images and vectors in this worksheet. They are not b y themselves interesting. At the end is commented out expression which will display all the images together, one row per class. " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 400 "displayMatrixAsImage := proc(A,max Val)\n local rs, cs, i, j, Poly, val:\n Poly := [];\n for i from 1 to rowdim(A) do\n for j from 1 to coldim(A) do\n val \+ := convert(A[i,j] / maxVal,float):\n Poly := [op(Poly), \n \+ POLYGONS([[i, j, A[i,j]], [i, j+1, A[i,j]], [i+1, j+1, A[i,j]], [ i+1, j, A[i,j]]],\n COLOR(RGB,val,val,val))]:\n \+ od:\n od:\n Poly:\nend: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 503 "displayMatrixAsImageAppend := proc(Lst, A, maxVal, offr, offc) \n local rs, cs, i, j, ri, ci, val, Poly:\n Poly := Lst:\n for i from 1 to rowdim(A) do\n for j from 1 to coldim(A) do\n \+ val := convert(A[i,j] / maxVal,float):\n ri := i + offr:\n \+ ci := j + offc:\n Poly := [op(Poly), \n \+ POLYGONS([[ri, ci, A[i,j]], [ri, ci+1, A[i,j]], [ri+1, ci+1, A[i, j]], [ri+1, ci, A[i,j]]],\n COLOR(RGB,val,val,val))]: \n od:\n od:\n Poly:\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 753 "displayImages := proc(imageList,maxVal)\n local i, samples, ims, offr, offc:\n ims := []:\n samples := floor(tra iningSize/3):\n offr := 0:\n offc := 0:\n for i from 1 to \+ samples do\n ims := displayMatrixAsImageAppend(ims,imageList[i],m axVal,offr, offc):\n offc := offc + imageSize + 2:\n od:\n of fr := offr + imageSize+2:\n offc := 0:\n for i from samples + 1 to 2*samples do\n ims := displayMatrixAsImageAppend(ims,imageL ist[i],maxVal,offr, offc):\n offc := offc + imageSize + 2:\n od :\n offr := offr + imageSize+2:\n offc := 0:\n for i from 2 *samples+1 to 3*samples do\n ims := displayMatrixAsImageAppend(im s,imageList[i],maxVal,offr, offc):\n offc := offc + imageSize + 2 :\n od:\n ims:\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 83 "#display(displayImages(trainImages,10),orientation=[0.0,0.0],scaling= CONSTRAINED);\n" }}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 23 "Fix Precision of Floats" }}{PARA 0 "" 0 "" {TEXT -1 281 " Maple is awkward in its \+ display of floats. Unless one actually changes the precision, it appea rs impossible to change the way the pretty printer does display. The f ollowing routine is used to reduce the precision of elements in arrays so they print in a relatively compact form. " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 192 "roundSigDigits := proc(x,d)\n local val, save Digits:\n saveDigits := Digits:\n Digits := d:\n val \+ := convert(round(x*10^d)/10^d,float):\n Digits := saveDigits:\n \+ val:\nend:" }}}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 24 "Generate Train ing Images" }}{PARA 0 "" 0 "" {TEXT -1 426 "Let us create a vector of \+ training images based upon three random image generators. Each of the se will generate an image based upon a particular pattern plus noise. \+ The noise is Gaussian with zero mean and sigma 1.0. The images are fou r pixels on a side. The first class has a bright square in the center, the second class is alternating bright and dark vertical bars, class \+ 3 is alternating bright and dark horizontal bars. " }}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 21 "Add Noise to an Image" }}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 175 "addNoise := proc(A,n)\n local noise, i, j:\n f or i from 1 to n do\n for j from 1 to n do\n A[i,j] := A[ i,j] + random[normald]():\n od:\n od:\n eval(A):\nend:" }}}} {SECT 0 {PARA 4 "" 0 "" {TEXT -1 13 "Image Class 1" }}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 191 "imageClass1 := proc(n,low,high)\n local A, i, j:\n A := matrix(n, n, low):\n for i from 2 to n-1 do \n for j from 2 to n-1 do\n A[i,j] := high:\n od:\n od:\n addNo ise(A,n):\n end:" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 13 "Image Clas s 2" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 192 "imageClass2 := proc( n,low,high)\n local A, i, j:\n A := matrix(n, n, low):\n for i from 1 to n do \n for j from 1 to n by 2 do\n A[i,j] := high:\n od:\n od:\n addNoise(A,n):\n end:" }}}}{SECT 0 {PARA 4 "" 0 " " {TEXT -1 13 "Image Class 3" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 192 "imageClass3 := proc(n,low,high)\n local A, i, j:\n A := matrix( n, n, low):\n for j from 1 to n do \n for i from 1 to n by 2 do\n A[i,j] := high:\n od:\n od:\n addNoise(A,n):\n end:" }} }}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 35 "Procedure to create Training Im ages" }}{PARA 0 "" 0 "" {TEXT -1 124 "As currently setup, this procedc ure produces 9 training images, 3 from each class. The are ordered fro m class 1 to class 3. " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 459 "t rainingImages := proc(size,n,low,high)\n local samples, data, k, s: \n samples := floor(size/3):\n data := vector(3*samples):\n k := 1:\n for s from 1 to samples do\n data[k] := imageCla ss1(n,low,high):\n k := k + 1:\n od:\n for s from 1 to sample s do\n data[k] := imageClass2(n,low,high):\n k := k + 1:\n \+ od:\n for s from 1 to samples do\n data[k] := imageClass3(n,lo w,high):\n k := k + 1:\n od:\n eval(data):\nend:" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 37 "Global call to create Training Images" }}{PARA 0 "" 0 "" {TEXT -1 197 "Here we bind T to the vector of traini ng images. Note that the precision is alterred so that there are only \+ 2 digits right of the decimal. Also note that the default setting is s aved and restored. " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 168 "save Digits := Digits:\nDigits := 3:\ntrainImages := trainingIm ages(trainingSize,imageSize,imageLow,imageHigh):\nDigits := sav eDigits:\neval(trainImages);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#-%'vec torG6#7+-%'matrixG6#7%7%$\"$<$!\"#$\"$C#F.$\"##*F.7%$!#fF.$\"$*fF.$\"$ _$F.7%$\"$;#F.$\"$X\"F.$\"$>#F.-F(6#7%7%$\"$b\"F.$\"$D#F.$\"$%GF.7%$\" $8$F.$\"$X&F.$\"$[\"F.7%$\"#YF.F=$\"$1#F.-F(6#7%7%$\"#?F.$\"#CF.$\"$(= F.7%$\"#uF.$\"$6)F.$\"$'>F.7%$\"$u$F.$\"$^\"F.$\"$Y#F.-F(6#7%7%$\"$1'F .Fgo$\"$N(F.7%$\"$m'F.$\"$o\"F.$\"$$pF.7%$\"$$oF.F`o$\"$p&F.-F(6#7%7%$ \"$f(F.$\"$2\"F.$\"$M'F.7%$\"$s)F.$\"$:\"F.$\"$R&F.7%$\"$7(F.$\"$T\"F. $\"$1&F.-F(6#7%7%$\"$())F.$\"$_#F.$\"$'pF.7%$\"$m(F.$\"$e#F.$\"$e(F.7% $\"$/(F.$\"$a\"F.$\"$y(F.-F(6#7%7%$\"$]'F.$\"$\"oF.$\"$(oF.7%$\"$\"HF. $\"$'HF.$\"$(GF.7%$\"$U'F.$\"$'fF.$\"$2*F.-F(6#7%7%F]p$\"$r'F.$\"$%oF. 7%Fht$\"#VF.$\"#nF.7%$\"$x&F.Fbp$\"$E(F.-F(6#7%7%Fev$\"$3(F.$\"$X'F.7% $\"$%HF.$\"#^F.Fbw7%$\"$-'F.$\"$D)F.$\"$(zF." }}}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 17 "Images to Vectors" }}{PARA 0 "" 0 "" {TEXT -1 73 "Go down the list of training images and convert these to column vectors. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 503 "Thi s procedure takes advantage of some nice features of Maple. First, if \+ you convert an nxn matrix to a vector, it automatically unrolls the el ements in exactly the manner we want. The result is a true Maple vecto r. Next, you can normalize the vector to be of unit length with one co mand. Next, when you convert that vector to a matrix, it assumes you \+ want a column vector, which in this case works out well for display pu rposes. At this step, we will also subtract off the mean from each ima ge vector." }}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 36 "Procedure to Comput e the Mean Vector" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 95 "meanXcv := proc(size,X)\n local i:\n scalarmul(evalm(sum(eval(X)[i],i=1.. size)),1/size):\nend:" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 45 "Proced ure to Map images to normalized vectors" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 300 "mapImagesToVectors := proc(size,n,Images)\n local \+ s, X, Xmu:\n X := vector(size):\n for s from 1 to size do\n X [s] := convert(normalize(convert(Images[s],vector)),matrix):\n od:\n Xmu := meanXcv(size,X):\n for s from 1 to size do\n X[s] := \+ evalm(X[s] - Xmu):\n od:\n eval(X):\nend:\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 35 "A ctually Perform Mapping to Vectors" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 "Xcvs := mapImagesToVectors(trainingSize,imageSize,tra inImages):\n" }}}{SECT 0 {PARA 5 "" 0 "" {TEXT -1 43 "Make a version w hich is better for printing" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 129 "Xcvsr := vector(trainingSize):\nfor i from 1 to trainingSize do\n Xcvsr[i] := map(roundSigDigits,Xcvs[i],3):\nod:\nX = eval(Xcvsr);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%\"XG-%'vectorG6#7+-%'matrixG6#7+7# $\"$5$!\"%7#$\"$S#F07#$!$F#!\"$7#$!$:$F77#$\"$%QF77#$\"$k\"F77#$!$!zF0 7#$!$S&F07#$!$0\"F7-F*6#7+7#$!$R\"F77#$\"$!\\F07#$\"$I#F07#$\"$X\"F77# $\"$!QF7FD7#$!$p#F77#$!$!RF07#$!$!)*F0-F*6#7+7#$!$7$F77#$!$3#F77#$!$U \"F77#$!$r\"F77#$\"$D&F7Fin7#$\"$]&F07#$!$g'F0FG-F*6#7+7#$\"$I$F07#$!$ S)F07#$\"$5\"F77#$\"$b\"F77#$!$,#F77#$\"$z\"F77#$\"$g)F07#$!$-\"F77#$! $I\"F0-F*6#7+7#$\"$=\"F77#$!$p\"F77#$\"$S%F07#$\"$r#F77#$!$M#F77#$\"$5 )F07#$\"$q*F07#$!$P\"F77#$!$g&F0-F*6#7+7#$\"$H\"F77#$!$,\"F77#$\"$+$F0 7#$\"$_\"F77#$!$o\"F77#$\"$c\"F77#$\"$5%F07#$!$S\"F7FP-F*6#7+F-7#$\"$[ \"F77#$\"$5&F0F]qF]tFAFjp7#$\"$8\"F77#$\"$^\"F7-F*6#7+7#$FenF07#$\"$y \"F77#$\"$])F07#$!$!pF07#$!$w#F77#$!$)>F77#$\"$g#F07#$\"$'=F77#$\"$!)) F0-F*6#7+7#$\"$?(F07#$\"$j\"F77#$\"$q#F07#$!$I)F07#$!$u#F77#$!$6#F77#$ \"$+\"F07#$F3F77#$\"$!*)F0" }}}}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 32 "Brute Force, Look at C orrelation" }}{PARA 0 "" 0 "" {TEXT -1 163 "Let us compute the cross c orrelation between all pairs of images. Note that we will go back to o riginal images, do the normalization, but do NOT remove the mean. " } }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 363 "imageCrossCorrelations := \+ proc(size,n,Images)\n local s1, s2, X, CC:\n CC := matrix(size,siz e):\n for s1 from 1 to size do\n for s2 from 1 to size do\n \+ CC[s1,s2] := roundSigDigits(dotprod(normalize(convert(Images[s1], vector)),\n normalize(conv ert(Images[s2],vector))),3):\n od:\n od:\n eval(CC):\nend:" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 80 "CC := imageCrossCorrelatio ns(trainingSize,imageSize,trainImages):\nCC = eval(CC);" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#/%#CCG-%'matrixG6#7+7+$\"\"\"\"\"!$\"$1)!\"$$\"$ h)F/$\"$P'F/$\"$b&F/$\"$q'F/$\"$4(F/$\"$t&F/$\"$y&F/7+F-F*$\"$D)F/$\"$ 3(F/$\"$l'F/$\"$<(F/$\"$K(F/$\"$S'F/$\"$C'F/7+F0F?F*F4$\"$#\\F/$\"$c&F /$\"$(eF/$\"$\\%F/$\"$R%F/7+F2FAF4F*$\"$x*F/$\"$()*F/$\"$q)F/$\"$=)F/$ \"$#zF/7+F4FCFNFYF*$\"$y*F/$\"$6)F/$\"$t(F/$\"$`(F/7+F6FEFPFenF^oF*$\" $r)F/$\"$3)F/$\"$!zF/7+F8FGFRFgnF`oFgoF*FY$\"$q*F/7+F:FIFTFinFboFioFYF *$\"$'**F/7+F " 0 "" {MPLTEXT 1 0 195 "unass ign('i','a','b','c','d','P','k'):\nPis := matrix(4,1, [a[i], b[i], c[i ], d[i]]):\nMis := matrix(4,1, [mu[a],mu[b],mu[c],mu[d]] ):\nVis := ev alm(Pis - Mis):\n[P[i] = eval(Pis), V[i] = eval(Vis)];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7$/&%\"PG6#%\"iG-%'matrixG6#7&7#&%\"aGF'7#&%\"bGF' 7#&%\"cGF'7#&%\"dGF'/&%\"VGF'-F*6#7&7#,&F.\"\"\"&%#muG6#F/!\"\"7#,&F1F A&FC6#F2FE7#,&F4FA&FC6#F5FE7#,&F7FA&FC6#F8FE" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 85 "[%?[i] = P, V[i] = matrix([[a[i]-mu[a]], [b[i]-m u[b]], [c[i]-mu[c]], [d[i]-mu[d]]])];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7$/&%#%?G6#%\"iG%\"PG/&%\"VGF'-%'matrixG6#7&7#,&&%\"aGF'\"\"\"&%#mu G6#F4!\"\"7#,&&%\"bGF'F5&F76#F=F97#,&&%\"cGF'F5&F76#FCF97#,&&%\"dGF'F5 &F76#FIF9" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 45 "Symbolic Equation \+ for 2x2 Covariance, General" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 120 "coVar := Sum(evalm(Vis &* transpose(Vis)), i=1..k):\nOmega = Sum( eval(Vis) * transpose(Vis),i=1..k);\nOmega = eval(coVar);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%&OmegaG-%$SumG6$*&-%'matrixG6#7&7#,&&%\"aG6#% \"iG\"\"\"&%#muG6#F0!\"\"7#,&&%\"bGF1F3&F56#F;F77#,&&%\"cGF1F3&F56#FAF 77#,&&%\"dGF1F3&F56#FGF7F3-F*6#7#7&F.F9F?FEF3/F2;F3%\"kG" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#/%&OmegaG-%$SumG6$-%'matrixG6#7&7&*$),&&%\"aG6#% \"iG\"\"\"&%#muG6#F1!\"\"\"\"#\"\"\"*&F/F4,&&%\"bGF2F4&F66#F>F8F4*&F/F :,&&%\"cGF2F4&F66#FDF8F4*&F/F:,&&%\"dGF2F4&F66#FJF8F47&F;*$)F " 0 "" {MPLTEXT 1 0 198 "\nOmeg a = Sum(eval(Pis) * transpose(Pis),i=1..3);\necoVar := evalm(Pis &* tr anspose(Pis)):\ncoVar := map(Sum,ecoVar,i=1..3):\nOmega = eval(coVar) ;\ncoVar := map(sum,ecoVar,i=1..3):\nOmega = eval(coVar);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%&OmegaG-%$SumG6$*&-%'matrixG6#7&7#&%\"aG6# %\"iG7#&%\"bGF07#&%\"cGF07#&%\"dGF0\"\"\"-F*6#7#7&F.F3F6F9F;/F1;F;\"\" $" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%&OmegaG-%'matrixG6#7&7&-%$SumG6 $*$)&%\"aG6#%\"iG\"\"#\"\"\"/F2;\"\"\"\"\"$-F+6$*&F/F7&%\"bGF1F7F5-F+6 $*&F/F4&%\"cGF1F7F5-F+6$*&F/F4&%\"dGF1F7F57&F9-F+6$*$)FFM-F+6$*$)FAF3F4F5-F+6$*&FAF4FFF4F57&FCF PFX-F+6$*$)FFF3F4F5" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%&OmegaG-%'mat rixG6#7&7&,(*$)&%\"aG6#\"\"\"\"\"#\"\"\"F0*$)&F.6#F1F1F2F0*$)&F.6#\"\" $F1F2F0,(*&F-F0&%\"bGF/F0F0*&F5F0&F?F6F0F0*&F9F0&F?F:F0F0,(*&F-F2&%\"c GF/F0F0*&F5F2&FGF6F0F0*&F9F2&FGF:F0F0,(*&F-F2&%\"dGF/F0F0*&F5F2&FOF6F0 F0*&F9F2&FOF:F0F07&F<,(*$)F>F1F2F0*$)FAF1F2F0*$)FCF1F2F0,(*&F>F2FFF2F0 *&FAF2FIF2F0*&FCF2FKF2F0,(*&F>F2FNF2F0*&FAF2FQF2F0*&FCF2FSF2F07&FDFfn, (*$)FFF1F2F0*$)FIF1F2F0*$)FKF1F2F0,(*&FFF2FNF2F0*&FIF2FQF2F0*&FKF2FSF2 F07&FLFjnFfo,(*$)FNF1F2F0*$)FQF1F2F0*$)FSF1F2F0" }}}}{SECT 0 {PARA 4 " " 0 "" {TEXT -1 39 "Consider the X matrix defined in Trucco" }}{PARA 0 "" 0 "" {TEXT -1 45 "Trucco defines the covariance in terms of an " }{XPPEDIT 18 0 "N^2;" "6#*$%\"NG\"\"#" }{TEXT -1 13 " by k matrix " } {XPPEDIT 18 0 "X;" "6#%\"XG" }{TEXT -1 74 " where each column is a dif fernt training image. The covariance matrix is " }{XPPEDIT 18 0 "Omega = X*X^T;" "6#/%&OmegaG*&%\"XG\"\"\")F&%\"TGF'" }{TEXT -1 51 ". To se e why this works out, consider our example." }}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 225 "unassign('a','b','c','d'):\nX := matrix(4,3):\nfor col from 1 to 3 do\n X[1,col] := a[col]: X[2,col] := b[col]: \n X [3,col] := c[col]: X[4,col] := d[col]: \nod:\nOmega = eval(X) * transp ose(X);\nOmega = evalm(X &* transpose(X));" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%&OmegaG*&-%'matrixG6#7&7%&%\"aG6#\"\"\"&F,6#\"\"#&F,6 #\"\"$7%&%\"bGF-&F7F0&F7F37%&%\"cGF-&FFCF." }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%&OmegaG-%'matrixG6#7&7&,(*$)&%\"aG6#\"\"\"\"\"#\"\"\"F0*$)&F.6#F1 F1F2F0*$)&F.6#\"\"$F1F2F0,(*&F-F0&%\"bGF/F0F0*&F5F0&F?F6F0F0*&F9F0&F?F :F0F0,(*&F-F2&%\"cGF/F0F0*&F5F2&FGF6F0F0*&F9F2&FGF:F0F0,(*&F-F2&%\"dGF /F0F0*&F5F2&FOF6F0F0*&F9F2&FOF:F0F07&F<,(*$)F>F1F2F0*$)FAF1F2F0*$)FCF1 F2F0,(*&F>F2FFF2F0*&FAF2FIF2F0*&FCF2FKF2F0,(*&F>F2FNF2F0*&FAF2FQF2F0*& FCF2FSF2F07&FDFfn,(*$)FFF1F2F0*$)FIF1F2F0*$)FKF1F2F0,(*&FFF2FNF2F0*&FI F2FQF2F0*&FKF2FSF2F07&FLFjnFfo,(*$)FNF1F2F0*$)FQF1F2F0*$)FSF1F2F0" }}} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 " " {TEXT -1 30 "Covariance for Training Images" }}{PARA 0 "" 0 "" {TEXT -1 148 "Now we are ready to compute the actual numeric covarianc e matrix for our training images. To start, we want to create the X ma trix defined in trucco" }}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 29 "Procedu re to create X matrix." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 230 "m apVectorsToX := proc(size,n,Xcvs)\n local X, V, col, i:\n X := mat rix((n*n),size):\n for col from 1 to size do\n V := Xcvs[col]: \n for i from 1 to (n*n) do\n X[i,col] := V[i,1]:\n \+ od:\n od:\n eval(X):\nend:" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 37 "Actually create the Covariance Matrix" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 244 "saveDigits := Digits:\nDigits := 10:\nXm \+ := mapVectorsToX(trainingSize,imageSize,Xcvs):\ncoVar := evalm(X m &* transpose(Xm)):\nDigits := saveDigits:\nX = map(roundSigDigit s,eval(Xm),3);\nOmega = map(roundSigDigits,eval(coVar),3);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%\"XG-%'matrixG6#7+7+$\"$5$!\"%$!$R\"!\"$$! $7$F/$\"$I$F,$\"$=\"F/$\"$H\"F/F*$\"$!QF,$\"$?(F,7+$\"$S#F,$\"$!\\F,$! $3#F/$!$S)F,$!$p\"F/$!$,\"F/$\"$[\"F/$\"$y\"F/$\"$j\"F/7+$!$F#F/$\"$I# F,$!$U\"F/$\"$5\"F/$\"$S%F,$\"$+$F,$\"$5&F,$\"$])F,$\"$q#F,7+$!$:$F/$ \"$X\"F/$!$r\"F/$\"$b\"F/$\"$r#F/$\"$_\"F/FC$!$!pF,$!$I)F,7+$\"$%QF/$F 9F/$\"$D&F/$!$,#F/$!$M#F/$!$o\"F/$!$P\"F/$!$w#F/$!$u#F/7+$\"$k\"F/$!$S &F,$!$!RF,$\"$z\"F/$\"$5)F,$\"$c\"F/$!$!zF,$!$)>F/$!$6#F/7+F\\r$!$p#F/ $\"$]&F,$\"$g)F,$\"$q*F,$\"$5%F,F2$\"$g#F,$\"$+\"F,7+FbqFdq$!$g'F,$!$- \"F/Fip$!$S\"F/$\"$8\"F/$\"$'=F/$F>F/7+$!$0\"F/$!$!)*F,F^t$!$I\"F,$!$g &F,F?$\"$^\"F/$\"$!))F,$\"$!*)F," }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/% &OmegaG-%'matrixG6#7+7+$\"$d\"!\"$$\"$g%!\"%$\"$S&F/$\"$!pF/$!$&HF,$\" $]$F/$\"$+%F/$\"$]\"F/$\"$q&F/7+F-$\"$s\"F,$\"$I$F/$!$q(F/$!$@\"F,$!$; \"F,$!$I%F/$\"$X\"F,$\"$?(F/7+F0FA$\"$!)*F/$\"$?\"F,$!$H#F,$!$?$F/$\"$ I#F/$\"$!GF/$\"$?&F/7+F2FCFR$\"$*GF,$!$A#F,$\"$!eF/$\"$q\"F/$!$S*F/$\" $+\"!\"&7+F4FEFTF[o$\"$h)F,$\"$S'F/$!$k\"F,$!$F\"F,$!$%>F,7+F6FGFVF]oF io$\"$%=F,$\"$!>F/$!$_\"F,$!$]&F/7+F8FIFXF_oF[pFdp$\"$-\"F,$!$+'Feo$\" $?$F/7+F:FKFZFaoF]pFfpF]q$\"$j\"F,$\"$I(F/7+F " 0 "" {MPLTEXT 1 0 318 "reduceToThreeDigits := proc(x)\n local saveDigits, new, intpart:\n saveDigits := Digits:\n Digits := 3:\n intp art := round(x*100.0):\n if (intpart = 1) then\n new := 0.01: \n elif (intpart = -1) then\n new := -0.01:\n else\n new : = intpart/100.0:\n fi:\n Digits := saveDigits: \n new:\nend: " }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 53 "Use SVD to generate rotatio n matrix and eigen values" }}{PARA 0 "" 0 "" {TEXT -1 184 "The call t o Svd will perform singular value decomposition on the covariance matr ix. The result are the elements of the diagonal matrix, as well as the pre- and post-multiply matrices: " }{XPPEDIT 18 0 "Um;" "6#%#UmG" } {TEXT -1 5 " and " }{XPPEDIT 18 0 "Vm;" "6#%#VmG" }{TEXT -1 3 ". " }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 109 "Um := matrix(imageSize*imag eSize,imageSize*imageSize):\nVm := matrix(imageSize*imageSize,imageSiz e*imageSize):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 176 "Lambda := evalf(Svd(coVar,Um,Vm)):\nDm := matrix(imageSize*imageSize,imageSize* imageSize,0.0):\nfor i from 1 to imageSize*imageSize do Dm[i,i] := rou ndSigDigits(Lambda[i],3): od:" }}}{SECT 0 {PARA 5 "" 0 "" {TEXT -1 25 " Show the diagonalization" }}{PARA 0 "" 0 "" {TEXT -1 51 "Show the di agonalization as well as the check that " }{XPPEDIT 18 0 "Omega = U*D* U^T;" "6#/%&OmegaG*(%\"UG\"\"\"%\"DGF')F&%\"TGF'" }{TEXT -1 1 "." }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 284 "coVar3 := map(roundSigDigit s,eval(coVar),2):\nUm3 := map(roundSigDigits,eval(Um),2):\nDm3 : = map(roundSigDigits,eval(Dm),2):\n#eval(Um3) * eval(Dm3) * transpose( Um3);\n eval(Um3) * eval(Dm3) * transpose(Um3);\neval(coVar3) = map(ro undSigDigits,evalm(Um3 &* Dm3 &* transpose(Um3)),3);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#*(-%'matrixG6#7+7+$!#H!\"#$!#!)!\"$$!#JF+$!#^F+$\"#S F+$\"#IF+$!#F+FhrFhrFhrFhrFhrFhr7+FhrFhrFhrF\\oFhrFhrFhrFhrFhr7+FhrFhrFhrFhr$F 6F.FhrFhrFhrFhr7+FhrFhrFhrFhrFhr$FAF.FhrFhrFhr7+FhrFhrFhrFhrFhrFhrFhrF hrFhrF[tF[tFir-F%6#7+7+F)FFOFhnFeoFcpFfoF[rFY7 +F/F@FQFjnFYFepF^qFapFhq7+F1FBFSFOFfoFgpF`qFapFS7+F3FDFUF\\oFhoFipF,F \\rFdr7+F5F7F)FYFjoF)FbqF^rFfr7+F7FFFWFSF\\pFJFdqF`rFjo7+F9FHFYF^oF^pF [qFfqFcpFhr7+F1FJFenF`oFHFapFhqFMFeoFir" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#/-%'matrixG6#7+7+$\"#;!\"#$\"#]!\"$F,$\"#qF.$!#IF+$\"#SF.F3$\"#? F.$\"#gF.7+F,$\"#FI$\"#HF+$!#AF+F7F5$!#!*F.\"\"!7+F1F@FKF Q$\"#')F+F7$!#;F+$!#8F+$!#>F+7+F3F@FMF7F7$\"#=F+F5$!#:F+$!#gF.7+F3FBF5 F5FYF5FG$!#5F.F<7+F5FDF\"F.$!$B#F.$!$!GF_p$\"$?#F_p $\"$q#F_pF`p7+FbpFcqFbr$\"$\"HF.Fdr$\"$?'F_p$F\\pF_p$!$]*F_p$\"$+#!\"& 7+FdpFeqFdrFdr$\"$a)F.$\"$I'F_p$!$i\"F.$!$H\"F.$!$(>F.7+FfpFgqFfrF_sFj s$\"$&=F.Fjp$!$a\"F.$!$S&F_p7+FhpFiqFhrFasF\\tFjp$\"$+\"F.$!$+%FfsFfp7 +FjpF[rFjrFbsF^tFetF\\u$\"$k\"F.$\"$S(F_p7+F\\qF]rF`pFdsF`tFgtFfpFau$ \"$q(F_p" }}}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 44 "Do projection by u sing first 3 eigenvectgors" }}{PARA 0 "" 0 "" {TEXT -1 315 " Here we \+ consider what the distribution of images looks like when projecting in to a 3-dimensional subspace associated with the first three (largest t hree) eigenvectors. This will culminate in a 3D point plot where the c lass 1 images are shown in red, the class two images in greeen and the class 3 images in blue. " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 119 "projMat := submatrix(Um,1..(imageSize*imageSize),1..3):\nprojMat 3 := map(roundSigDigits,projMat,3):\nS = eval(projMat3);" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#/%\"SG-%'matrixG6#7+7%$!$&G!\"$$!$S)!\"%$!$9$F,7 %$!$Q\"F,$\"$j%F,$\"$-\"F,7%$!$M#F,$!$q&F/$\"$U$F,7%$!$H#F,$!$;&F,$\"$ U'F,7%$\"$U)F,$\"$!QF/$\"$e\"F,7%$\"$5)F/$!$p%F,$!$C%F,7%$!$U\"F,$!$. \"F,$!$%QF,7%$!$O\"F,$\"$+&F,$\"$?)F/7%$!$'>F,$\"$j\"F,$!$5&F/" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 140 "pts := evalm(transpose(proj Mat) &* Xm):\nXm3 := map(roundSigDigits,Xm,3):\nP = transpose(Xm3) * e val(projMat3);\nP = map(roundSigDigits,pts,3);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#/%\"PG*&-%'matrixG6#7+7+$\"$5$!\"%$\"$S#F-$!$F#!\"$$!$: $F2$\"$%QF2$\"$k\"F2$!$!zF-$!$S&F-$!$0\"F27+$!$R\"F2$\"$!\\F-$\"$I#F-$ \"$X\"F2$\"$!QF2F;$!$p#F2$!$!RF-$!$!)*F-7+$!$7$F2$!$3#F2$!$U\"F2$!$r\" F2$\"$D&F2FL$\"$]&F-$!$g'F-F=7+$\"$I$F-$!$S)F-$\"$5\"F2$\"$b\"F2$!$,#F 2$\"$z\"F2$\"$g)F-$!$-\"F2$!$I\"F-7+$\"$=\"F2$!$p\"F2$\"$S%F-$\"$r#F2$ !$M#F2$\"$5)F-$\"$q*F-$!$P\"F2$!$g&F-7+$\"$H\"F2$!$,\"F2$\"$+$F-$\"$_ \"F2$!$o\"F2$\"$c\"F2$\"$5%F-$!$S\"F2FB7+F+$\"$[\"F2$\"$5&F-F\\oF[qF9F jn$\"$8\"F2$\"$^\"F27+$FIF-$\"$y\"F2$\"$])F-$!$!pF-$!$w#F2$!$)>F2$\"$g #F-$\"$'=F2$\"$!))F-7+$\"$?(F-$\"$j\"F2$\"$q#F-$!$I)F-$!$u#F2$!$6#F2$ \"$+\"F-$F/F2$\"$!*)F-\"\"\"-F'6#7+7%$!$&GF2F\\o$!$9$F27%$!$Q\"F2$\"$j %F2$\"$-\"F27%Fep$!$q&F-$\"$U$F27%$!$H#F2$!$;&F2$\"$U'F27%$\"$U)F2Fjr$ \"$e\"F27%Fgp$!$p%F2$!$C%F27%FU$!$.\"F2$!$%QF27%$!$O\"F2$\"$+&F2$\"$?) F-7%$!$'>F2F^t$!$5&F-F]u" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%\"PG-%'m atrixG6#7%7+$\"$*[!\"$$\"$t$F,$\"$^'F,$!$4#F,$!$d#F,$!$!>F,$!$$>F,$!$M $F,$!$H$F,7+$\"$])!\"%$!$+\"F@$\"$+*!\"&$!$\"GF,$!$l$F,$!$%GF,$\"$;#F, $\"$(HF,$\"$K$F,7+$!$l#F,$\"$P$F,$!$+%FE$!$+$F@$\"$!=F@$!$]'F@FY$\"$?$ F@$\"$+(FE" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 560 "subspacePts \+ := proc(pts)\n local i, samples, dpts:\n dpts := []:\n sample s := floor(coldim(pts)/3):\n for i from 1 to samples do\n dpts \+ := [op(dpts),POINTS([pts[1,i], pts[2,i], pts[3,i]],SYMBOL(BOX),COLOR(R GB,1.0,0.0,0.0))]:\n od:\n for i from samples + 1 to 2*samples do \n dpts := [op(dpts),POINTS([pts[1,i], pts[2,i], pts[3,i]],SYMBOL (BOX),COLOR(RGB,0.0,1.0,0.0))]:\n od:\n for i from 2*samples+1 to \+ 3*samples do\n dpts := [op(dpts),POINTS([pts[1,i], pts[2,i], pts[ 3,i]],SYMBOL(BOX),COLOR(RGB,0.0,0.0,1.0))]:\n od:\n eval(dpts):\ne nd:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 114 "display(subspacePts (pts),axes=BOXED,labels=[\"PC 1\", \"PC 2\", \"PC 3\"],scaling=CONSTRA INED,font=[HELVETICA,BOLD,14]);" }}{PARA 13 "" 1 "" {GLPLOT3D 400 300 300 {PLOTDATA 3 "6/-%'POINTSG6%7%$\"+BnL\"*[!#5$\"+)[52`)!#6$!+V?-_EF) -%'SYMBOLG6#%$BOXG-%&COLORG6&%$RGBG$\"#5!\"\"\"\"!F:-F$6%7%$\"+$z'GDPF )$!*d0#R(*F,$\"+AC$*pLF)F/F3-F$6%7%$\"+f='*3lF)$\"*Uz0t)F,$!+UgGPQ!#7F /F3-F$6%7%$!+&pG\\4#F)$!+MrK9GF)$!+!Q)e'*HF,F/-F46&F6F:F7F:-F$6%7%$!+6 F1sDF)$!+t7_YOF)$\"+DeF'y\"F,F/FW-F$6%7%$!+4%Rm*=F)$!+tUBNGF)$!+pZ>DlF ,F/FW-F$6%7%$!+)p]\"H>F)$\"+ds=f@F)$!+5!oB.$F,F/-F46&F6F:F:F7-F$6%7%$! +*3:&RLF)$\"+O1drHF)$\"+'z*yDKF,F/F^p-F$6%7%$!+x()G$H$F)$\"+++MALF)$\" +/J5nuFMF/F^p-%%FONTG6%%*HELVETICAG%%BOLDG\"#9-%(SCALINGG6#%,CONSTRAIN EDG-%+AXESLABELSG6%Q%PC~16\"Q%PC~2F`rQ%PC~3F`r-%*AXESSTYLEGF1" 1 2 0 1 0 2 1 1 2 1 1.000000 45.000000 45.000000 0 }}}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}}}{MARK "8 4 3 2 0" 0 }{VIEWOPTS 1 1 0 2 1 1805 }