Local definitions

Segment loaded image

SegmentObject[img_, thresh_:245, color_:replacementColor] := Module[{img2}, im ... eplacementColor, #] & , img[[1, 1]], {2}] ; ReplacePart[img, img2, {1, 1}] ] ;

Segment file image

ConvertImage[outFile_, inFile_, type_, thresh_:245, color_:replacementColor] := Module ... = SegmentObject[img, thresh, color] ; Export[outFile, img2, "PPM"] ; ] ;

Extract RGB data from segmented images

ExtractRGB[img_, color_:replacementColor] := Module[{rgb}, rgb = Partition[Flatten[img[[1, 1]]], 3] ; DeleteCases[rgb, color] ] ;

Get representative sample of data

RepresentativeSample[dat_, n_] := Module[{d2, m}, m = Ceiling[Length[dat]/n] ; d2 = First /@ Partition[dat, m]] ;

Data plotting routines

Plot representative sample data (columns a and b from dat ) from a larger data set in 2d

PlotRepresentativeSample2D[dat_, n_, {a_, b_}, opt___] := Module[{d2, m, rgblabel}, &# ... [[a]], rgblabel[[b]]}, DisplayFunctionIdentity, PlotRange {{0, 255}, {0, 255}}]] ;

Plot representative sample data  from a larger data set in 3d

PlotRepresentativeSample3D[dat_, n_, opt___] := Module[{d2, m}, m = Ceiling[Le ... , Point/@ d2]], DisplayFunctionIdentity, PlotRange-> {{0, 255}, {0, 255}, {0, 255}}]] ;

RowBox[{data2pixel[{r_, g_, b_, x_, y_}], :=, RowBox[{{, RowBox[{RowBox[{RGBColor, [, RowBox[{ ... [{g, /, 255.}], ,, RowBox[{b, /, 255.}]}], ]}], ,,  , Rectangle[{x, -y - 1}, {x + 1, -y}]}], }}]}]

Plot multiple results for mixture model

EMAllPlot[{μ_, Σ_, priors_}, gin_] := Module[{pr, g2, g4, g5}, pr =  ... nS, AxesNone] ; Show[GraphicsArray[{{g2, gin}, {g4, g5}}], yS, imSize] ] ;

Classify image (2d)

OneClassClassifyImage2DAugmented[im_, pdf_, threshold_, which_: {Red, Green}, scale_:1] :=  ... ; threshold, gr, bl]] &, im[[1, 1]], {2}] ; ReplacePart[im, class, {1, 1}] ] ;

Full classify image (2d)

RowBox[{RowBox[{OneClassClassify2[model_, threshold_, obj_, obj2_], :=, , RowBox[{Modu ... df, ,, threshold, ,, {Red, Green}, ,, 255.}], ]}]}], ;, {class1, class2}}]}], , ]}]}], ;}]

OneClassError[class1_, class2_] := Module[{cnt1, cnt2, bar}, cnt1 = CountPixel ... ;FrameTrue, BarLabels {"Kellogs", "Tide"}, imSize] ] ;

Count pixels in classified images

CountPixels[classim_, color1_: (List @@ (pointStyle1 // First)) * 255, color2_: (List @@ (poin ... olor] // Flatten // First, 1]] ;  {100 * n1/(n1 + n2), 100 * n2/(n1 + n2)} // N] ;

3d EM initialization function

Scalar covariance initialization 3d

EMInitializationScalar3D[x_, k_] := Module[{n, rl, μ, σ, priors, sm, del2}, <br />&n ... riors = Table[1/k, {k}] // N ; <br />     {μ, σ, priors} ] ;

Full covariance initialization 3d

EMInitializationFull3D[x_, k_] := Module[{μ, σ, priors, dim},  {_ ... th[First[μ]] ;  {μ, (# IdentityMatrix[dim]) & /@ σ, priors} ] ;


Created by Mathematica  (October 9, 2003)