Frequency-based classification (2D)

Read in image files

brick = ReadWholeImage[BrickFile] ;  brickIm = brick ; wood = ReadWholeImage[WoodFile] ; woodIm = wood ;

size = brick[[1, 1]] // Dimensions // First ;

Show image files

Show[GraphicsArray[{{brick, wood}}], ImageSize400] ;

[Graphics:../HTMLFiles/index_34.gif]

Compute horizontal and vertical filtered images

filter = {1/4, -1/2, 1/4} // N ; filterH = Table[filter, {5}] ; filterV = filterH // Transpose ;

wood1 = ListConvolve[filterH, wood[[1, 1]], {-1, -1}] ; wood2 = ListConvolve[filterV, wood[[1, ... lve[filterH, brick[[1, 1]], {-1, -1}] ; brick2 = ListConvolve[filterV, brick[[1, 1]], {-1, -1}] ;

g1 = ListDensityPlot[#, MeshFalse, FrameFalse, PlotRangeAutomatic, DisplayFunctionIdentity] & /@ {wood1, wood2, brick1, brick2} ;

Show horizontal and vertical filtered images

RowBox[{RowBox[{Show, [, RowBox[{GraphicsArray[Partition[g1, 2]], ,, ImageSize400, ,,  , RowBox[{GraphicsSpacing, , 0.02}]}], ]}], ;}]

[Graphics:../HTMLFiles/index_39.gif]

Compute two-dimensional (horiztonal/vertical) feature vectors

pr = {{-100, 100}, {-100, 100}} ;

wood3 = {Flatten[wood1], Flatten[wood2]} // Transpose ; brick3 = {Flatten[brick1], Flatten[brick2]} // Transpose ;

g1 = Show[Graphics[{Red, Point/@wood3}], AspectRatioAutomatic, PlotRangeAll, n ...  = Show[Graphics[{Blue, Point/@brick3}], AspectRatioAutomatic, PlotRangeAll, nS] ;

Visualize two-dimensional (horiztonal/vertical) feature vectors

distrr = Show[g1, g2, ImageSize288, FrameTrue, PlotRangepr, FrameTicksNone, yS] ;

[Graphics:../HTMLFiles/index_44.gif]

Compute two-dimensional pdfs

p1 = gaussian[brick3 //N, {x, y}] ; p2 = gaussian[wood3//N, {x, y}] ;

Show two-dimensional pdfs

ShowTwoGaussianPDFs[p1, p2, pr, x, y, ImageSize400] ;

[Graphics:../HTMLFiles/index_47.gif]

Compute decision regions

dec = ShowTwoClassificationRegions[p1, p2, pr, x, y, classColors, False, AxesFalse, FrameTrue, FrameTicksNone, nS] ;

Show decision regions

Show[GraphicsArray[{{dec, distrr}}], ImageSize400] ;

[Graphics:../HTMLFiles/index_50.gif]

Compute expected error

errors = ExpectedError2D[p1, p2, x, y]

7.86218

Classify training and test image

c1 = ClassifyImage2D[Partition[brick3, size], p1, p2] ; c2 = ClassifyImage2D[Partition[wood3, size], p1, p2] ;

Show classification results

Show[GraphicsArray[{{brickIm, c1}, {woodIm, c2}}], ImageSize400] ;

[Graphics:../HTMLFiles/index_55.gif]

Compute classification error

brickStats = First /@ Frequencies[Partition[Flatten[c1[[1, 1]]], 3]] ; woodStats = First /@&nb ... ]]], 3]] ; bar2 = {brickStats/(Plus @@ brickStats), woodStats/(Plus @@ woodStats)} // Transpose ;

Show classification error

BarChart[bar2[[1]], bar2[[2]], BarStyle {Blue, Orange}, FrameTrue, BarLabels {"Brick", "Wood"}, imSize] ;

[Graphics:../HTMLFiles/index_58.gif]


Created by Mathematica  (October 9, 2003)