2d mixture-of-Gaussians classification (GB plane)

Visualize distributions

which = {2, 3} ; gobj1 = PlotRepresentativeSample2D[data1, 2000, which, pointStyle1] ; gobj2 = ... meLabelNone, nS] ; gbase = Show[g1, g2, nS] ; Show[GraphicsArray[{g1, g2}], imSize, yS] ;

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

EM experiment #1: object 1 (Coke can)

Extract 2d data

RowBox[{RowBox[{d2d1, =, RowBox[{(, RowBox[{{#[[which[[1]]]], #[[which[[2]]]]} &, /@,  , RowBox[{(, RowBox[{data1, /, 255.}], )}]}], )}]}], ;}]

Choose number of Gaussians in mixture model

k = 3 ;

Assumes full covariance matrices (custom)

RowBox[{RowBox[{initFull,  , =,  , RowBox[{{, RowBox[{{{.1, .1}, {.5, .5}, {.9, .9}}, ,, ɯ ... trix[{.1, .1}], {3}], ,, RowBox[{RowBox[{{, RowBox[{1., ,, 1., ,, 1.}], }}], /, 3.}]}], }}]}], ;}]

Compute EM algorithm

RowBox[{Timing, [, RowBox[{RowBox[{em,  , =,  , RowBox[{EM, [, RowBox[{d2d1, ,, initFull, ,, 0.001}], ]}]}], ;}], ]}]

RowBox[{{, RowBox[{RowBox[{0.78,  , Second}], ,, Null}], }}]

Save solution

bad = Position[em, Indeterminate] ; If[Length[bad] >0, bad = bad//First//First] ;  em = If[NumberQ[bad] True, Take[em, {1, bad - 1}], em] ; model1 = em//Last ;

Final model

EMAllPlot[model1, g1] ;

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

EM experiment #2: object 2 (Coke Light can)

Extract 2d data

RowBox[{RowBox[{d2d2, =, RowBox[{(, RowBox[{{#[[which[[1]]]], #[[which[[2]]]]} &, /@,  , RowBox[{(, RowBox[{data2, /, 255.}], )}]}], )}]}], ;}]

Choose number of Gaussians in mixture model

k = 3 ;

Assumes full covariance matrices (custom)

RowBox[{RowBox[{initFull,  , =,  , RowBox[{{, RowBox[{{{.1, .1}, {.5, .5}, {.9, .9}}, ,, ɯ ... trix[{.1, .1}], {3}], ,, RowBox[{RowBox[{{, RowBox[{1., ,, 1., ,, 1.}], }}], /, 3.}]}], }}]}], ;}]

Compute EM algorithm

RowBox[{Timing, [, RowBox[{RowBox[{em,  , =,  , RowBox[{EM, [, RowBox[{d2d2, ,, initFull, ,, 0.001}], ]}]}], ;}], ]}]

RowBox[{{, RowBox[{RowBox[{6.56,  , Second}], ,, Null}], }}]

Save solution

bad = Position[em, Indeterminate] ; If[Length[bad] >0, bad = bad//First//First] ;  em = If[NumberQ[bad] True, Take[em, {1, bad - 1}], em] ; model2 = em//Last ;

Final model

EMAllPlot[model2, g2] ;

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

Resulting classification of 2d space

pts = 150 ; RowBox[{RowBox[{reg1,  , =, RowBox[{MixtureLikelihoodMatrix, [, RowBox[{RowBox[{{, ... n[If[#[[1]] < #[[2]], 1, 0] & /@ ({Flatten[reg1], Flatten[reg2]} // Transpose), pts + 1] ;

<br />classPlot1 = ListDensityPlot[class, ColorFunction-> (If[#0, pointStyle1[[1]], ... #62754;None, nS] ; Show[GraphicsArray[{{g1, g2}, {classPlot1, classPlot2}}], imSize, yS] ;

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

Image classification

pdf1 = MixtureLikelihoodNative[{x, y}, model1] ; pdf2 = MixtureLikelihoodNative[{x, y}, model2] ;

RowBox[{RowBox[{class1, =, RowBox[{ClassifyImage2DAugmented, [, RowBox[{obj1, ,, pdf1, ,, pdf2 ... ,, 255.}], ]}]}], ;}] Show[GraphicsArray[{{obj1, class1, obj2, class2}}], ImageSize400] ;

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

RowBox[{RowBox[{class1, =, RowBox[{ClassifyImage2DAugmented, [, RowBox[{obj1T, ,, pdf1, ,, pdf ...  255.}], ]}]}], ;}] Show[GraphicsArray[{{obj1T, class1, obj2T, class2}}], ImageSize400] ;

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

Error plot

cnt1 = CountPixels[class1] ; cnt2 = CountPixels[class2] ;

bar = {cnt1, cnt2} // Transpose ; BarChart[bar[[1]], bar[[2]], BarStyle {pointStyle1[[ ... #62371;FrameTrue, BarLabels {"Coke", "Coke Light"}, imSize] ;

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


Created by Mathematica  (October 9, 2003)