DWT-based texture segmentation: example set #2

Note: This notebook assumes that all definitions in ipcv_definitions.nb (ver. 1.2 or later) have been evaluated first. It also assumes that the directory in the Set image directory points to an image directory with the following images: texture5.gif, texture6.gif, texture7.gif and texture8.gif

Warning: This notebook was evaluated using externally C-compiled MathLink functions to speed up some of the computations, especially the training part of the notebook. Since this option is not available for the student version of Mathematica, this notebook performs all computations within Mathematica natively. It is therefore possible, depending on your platform, that computation times  far exceed those shown.

Local definitions

Training data generation

bandMap  =  {{1, 2, 1}, {1, 1, 2}, {1, 2, 2}, {2, 2, 1}, {2, 1, 
            2}, {2, 2, 2}};

GenerateSixBandTrainingData[m_,  part_,  
          lpf_] := 
Module[{m1, m2, b1, 
            b2}, 
m1 = 
            Flatten[Partition[m, {16, 16}, part], 
              1]; 
m2 = WaveletTransform2D[#,  lpf, 
                  2] &  /@  m1; 
b1 = 
            Abs[ExtractBands[#, 1] & /@  m2]; 
b2 = 
            Abs[ExtractBands[#, 2] & /@  
                m2]; 
{Flatten[#[[2, 1]]] &  /@  
              b1, 
Flatten[#[[1, 2]]] &  /@  
              b1, 
Flatten[#[[2, 2]]] &  /@  
              b1, 
Flatten[#[[2, 1]]] &  /@  
              b2, 
Flatten[#[[1, 2]]] &  /@  
              b2, 
Flatten[#[[2, 2]]] &  /@  
              b2}
];

Visualize centroids

VisualizeCentroids[means_,  
          opts___] := 
Module[{n, m, 
            g1}, 
n = 
            Sqrt[Length[First[means]]]; 
m = 
            Min[Length[means], 8]; 
g1 = 
            Table[ShowImage[Partition[means[[i]], n], 1, 
                Max[means[[i]]], Min[means[[i]]], 
                DisplayFunction -> Identity], {i, 1, 
                Length[means]}]; 
Show[
            GraphicsArray[Partition[g1, m]], 
            DisplayFunction -> $DisplayFunction, 
            opts]
];

Histogram computation

ComputeHistograms[cls_,  
          nCodes_:  
            6] := 
N[
              CategoryCounts[#, Table[i, {i, 1, 2^nCodes}]]/
                Length[#]] &  /@  cls;

Classification functions

ProbabilitiesOneHistogramOne[m_, lpf_,  centroids_,  
          hist_,  {level_, a_, b_}] := 
Module[{mw, 
            pos}, 
mw = 
            Abs[Flatten[ExtractBands[WaveletTransform2D[m,  lpf, 2], 
                    level][[a, b]]]]; 
pos  =  
            AssignClassOne[mw, 
              centroids]; 
(#[[pos]]) &  /@  
            hist
];

ProbabilitiesOneHistogram[mp_, lpf_,  centroids_,  
          hist_,  {level_, a_, b_}] := 
Map[
          ProbabilitiesOneHistogramOne[#, lpf, centroids, 
              hist, {level, a, b}] &, mp, {2}];

ProbabilitiesAllHistograms[mp_,  lpf_,  centroids_,  hist_, 
          bandMap_] := 
Table[
          ProbabilitiesOneHistogram[mp, lpf, centroids[[i]], 
            hist[[i]],  bandMap[[i]]], {i, 1, 
            Length[bandMap]}];

AnalyzeOneImage[img_,  part_,  lpf_,  centroids_,  hist_,  
          bandMap_] := 
Module[{mt, 
            probs}, 
mt = 
            Partition[img, {16, 16},  part]; 
probs = 
            ProbabilitiesAllHistograms[mt, lpf, centroids, hist, 
              bandMap]
];

ClassifyOnProbabilities[probs_] := 
Map[
          First[First[Position[#, Max[#]]]] &, probs, {2}];

VisualizeClassification[cls_,  colors_,  
          opts___] := 
Show[
          Graphics[RasterArray[Map[colors[[#]] &,  cls,  {2}]]],  
          AspectRatio -> Automatic, opts];

ClassificationPercentages[cls_, 
          n_] := 
Module[{pct}, 
pct = 
            CategoryCounts[cls // Flatten, Range[n]]; 
100 
               pct/(Plus  @@  pct)  //  
            N
];

VisualizeResults[probs_,  colors_, 
          opts___] := 
Module[{cls, g1, pct, g2, g2b, 
            pr}, 
cls = 
            ClassifyOnProbabilities[probs]; 
g1 = 
            VisualizeClassification[cls, colors,  
              DisplayFunction -> Identity]; 
pct = 
            ClassificationPercentages[cls, 
              Length[probs // First // First]]; 
 
          g2 = BarChart[pct, BarStyle -> colors, 
              BarEdgeStyle -> colors, Frame -> True,  
              DisplayFunction -> Identity]; 
pr = 
            FullOptions[g2, PlotRange]; 
g2b = 
            Show[g2, PlotRange -> {pr // First, {-2, 102}},  
              GridLines -> {None, Automatic},  
              FrameTicks -> None,  
              Axes -> False]; 
{pct, 
            Show[GraphicsArray[{{g1}, {g2b}}], opts, 
              DisplayFunction -> $DisplayFunction]}
];

Set image directory

If[StringQ[$ImagePath], $path = $ImagePath,  $path = "."]; 
    SetDirectory[$path];

Sample texture images

imageList = 
      Table["texture" <> ToString[i] <> ".gif", {i, 5, 8}]

texImages = ReadImage  /@  imageList;

gImages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          texImages;
Show[GraphicsArray[Partition[gImages, 2]], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];

Train histogram models

Visualize training data

trainPos1 = {161, 1};
trainPos2 = {320, 320};
trainOffset = {4, 4};

trainingVis = 
BlockMatrix[
          Partition[TakeMatrix[#, trainPos1, trainPos2] &  /@  
              texImages, 2]];
ShowImage[trainingVis];

Generate six-band training data (top half of each image)

time1 = AbsoluteTime[];
db4 = DaubechiesFilter[4];
trainingData1 = GenerateSixBandTrainingData[
              TakeMatrix[#, trainPos1, trainPos2], trainOffset, db4] & /@  
          texImages;
AbsoluteTime[] - time1

Perform vector quantization for each band

maxCodes = 6;

time1 = AbsoluteTime[];
trainingData2 = (trainingData1  //  
            Transpose);
vqTrainingData = Flatten[#, 1] &  /@  
          trainingData2;
centroidsAll = VQAll[#, maxCodes,  .0001] &  /@  
          vqTrainingData;
AbsoluteTime[] - time1

centroidsAll  =  
        Drop[centroidsAll  //  Transpose, 1];

Compute histograms for all levels of quantization

time1 = AbsoluteTime[];
classes = 
        Table[centroids = centroidsAll[[i]]; 
          Table[AssignClass[#, centroids[[j]]] &  /@  
              trainingData2[[j]], {j, 1, Length[centroids]}], {i, 1, 
            maxCodes}];
AbsoluteTime[] - time1

histAll = 
        Table[ComputeHistograms[#, codes] &  /@  
            classes[[codes]], {codes, 1, maxCodes}];

Analysis and testing #1 (2 clusters per band)

Level of quantization

Select level of quantization (1, 2, 3, 4, 5, 6)

vqlevel = 1;

Pick corresponding VQ codebook and histograms

centroids = centroidsAll[[vqlevel]];
hist = histAll[[vqlevel]];

Visualize centroids by band

The graphics below illustrate the centroids by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

VisualizeCentroids[#, ImageSize -> 500] &  /@  
        centroids;

Visualize histograms

The graphics below illustrate the histogram over the VQ codebooks by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

colors = {Red, Green, Blue, Orange};

BarChart[Sequence  @@  #, BarStyle -> colors, 
            BarEdgeStyle -> colors, Frame -> True, 
            ImageSize -> 500] &  /@  hist;

Visualize test images

Define test image data

testPos1 = {1, 1};
testPos2 = {160, 320};
testOffset = {4, 4};

Visualize test image data

testData = TakeMatrix[#, testPos1, testPos2] &  /@  
          texImages;
testVis = 
BlockMatrix[
          Partition[testData, 2]];
ShowImage[testVis];

Compute all test image probabilities

Define filter (same as used during training)

db4 = DaubechiesFilter[4];

Compute probabilities for all test images and all histogram models

time1 = AbsoluteTime[];
probs = AnalyzeOneImage[#, testOffset, db4, centroids, hist, 
              bandMap] &  /@  testData;
AbsoluteTime[] - time1

Visualize individual histogram classifications of test images

The graphics below illustrate the classification of each test image by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

results = 
        Map[VisualizeResults[#,  colors,  
              DisplayFunction -> Identity] &,  
          probs,  {2}];

gresults = Map[Last, results, {2}];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[Transpose[gresults]], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Visualize overall classifications of test images

resultsCombined = 
        Map[VisualizeResults[Times  @@ #,  colors,  
              DisplayFunction -> Identity] &,  probs];

gresultsCombined = 
        Map[Last, resultsCombined];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[gresultsCombined], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Summary of percent correct classification

By band (1 - HL1, 2 - LH1, 3 - HH1, 4 - HL2, 5 - LH2, 6 - HH3)

correctbyband = 
        Table[Map[First, results, {2}][[j, i, j]], {j, 1, 
            Length[testData]}, {i, 1, Length[bandMap]}];
BarChart[Sequence  @@  correctbyband, BarStyle -> colors, 
        BarEdgeStyle -> colors,  Frame -> True,  
        GridLines -> {None, Automatic}, 
        ImageSize -> 400];

Overall bands and overall correct classification percentage

correctoverall = 
        Table[Map[First, resultsCombined][[i, i]], {i, 1, 
            Length[testData]}];
BarChart[correctoverall,  BarStyle -> colors, 
        BarEdgeStyle -> colors, Frame -> True,  
        ImageSize -> 400];
Mean[correctoverall]

Analysis and testing #2 (4 clusters per band)

Level of quantization

Select level of quantization (1, 2, 3, 4, 5, 6)

vqlevel = 2;

Pick corresponding VQ codebook and histograms

centroids = centroidsAll[[vqlevel]];
hist = histAll[[vqlevel]];

Visualize centroids by band

The graphics below illustrate the centroids by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

VisualizeCentroids[#, ImageSize -> 500] &  /@  
        centroids;

Visualize histograms

The graphics below illustrate the histogram over the VQ codebooks by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

colors = {Red, Green, Blue, Orange};

BarChart[Sequence  @@  #, BarStyle -> colors, 
            BarEdgeStyle -> colors, Frame -> True, 
            ImageSize -> 500] &  /@  hist;

Visualize test images

Define test image data

testPos1 = {1, 1};
testPos2 = {160, 320};
testOffset = {4, 4};

Visualize test image data

testData = TakeMatrix[#, testPos1, testPos2] &  /@  
          texImages;
testVis = 
BlockMatrix[
          Partition[testData, 2]];
ShowImage[testVis];

Compute all test image probabilities

Define filter (same as used during training)

db4 = DaubechiesFilter[4];

Compute probabilities for all test images and all histogram models

time1 = AbsoluteTime[];
probs = AnalyzeOneImage[#, testOffset, db4, centroids, hist, 
              bandMap] &  /@  testData;
AbsoluteTime[] - time1

Visualize individual histogram classifications of test images

The graphics below illustrate the classification of each test image by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

results = 
        Map[VisualizeResults[#,  colors,  
              DisplayFunction -> Identity] &,  
          probs,  {2}];

gresults = Map[Last, results, {2}];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[Transpose[gresults]], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Visualize overall classifications of test images

resultsCombined = 
        Map[VisualizeResults[Times  @@ #,  colors,  
              DisplayFunction -> Identity] &,  probs];

gresultsCombined = 
        Map[Last, resultsCombined];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[gresultsCombined], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Summary of percent correct classification

By band (1 - HL1, 2 - LH1, 3 - HH1, 4 - HL2, 5 - LH2, 6 - HH3)

correctbyband = 
        Table[Map[First, results, {2}][[j, i, j]], {j, 1, 
            Length[testData]}, {i, 1, Length[bandMap]}];
BarChart[Sequence  @@  correctbyband, BarStyle -> colors, 
        BarEdgeStyle -> colors,  Frame -> True,  
        GridLines -> {None, Automatic}, 
        ImageSize -> 400];

Overall bands and overall correct classification percentage

correctoverall = 
        Table[Map[First, resultsCombined][[i, i]], {i, 1, 
            Length[testData]}];
BarChart[correctoverall,  BarStyle -> colors, 
        BarEdgeStyle -> colors, Frame -> True,  
        ImageSize -> 400];
Mean[correctoverall]

Analysis and testing #3 (8 clusters per band)

Level of quantization

Select level of quantization (1, 2, 3, 4, 5, 6)

vqlevel = 3;

Pick corresponding VQ codebook and histograms

centroids = centroidsAll[[vqlevel]];
hist = histAll[[vqlevel]];

Visualize centroids by band

The graphics below illustrate the centroids by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

VisualizeCentroids[#, ImageSize -> 500] &  /@  
        centroids;

Visualize histograms

The graphics below illustrate the histogram over the VQ codebooks by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

colors = {Red, Green, Blue, Orange};

BarChart[Sequence  @@  #, BarStyle -> colors, 
            BarEdgeStyle -> colors, Frame -> True, 
            ImageSize -> 500] &  /@  hist;

Visualize test images

Define test image data

testPos1 = {1, 1};
testPos2 = {160, 320};
testOffset = {4, 4};

Visualize test image data

testData = TakeMatrix[#, testPos1, testPos2] &  /@  
          texImages;
testVis = 
BlockMatrix[
          Partition[testData, 2]];
ShowImage[testVis];

Compute all test image probabilities

Define filter (same as used during training)

db4 = DaubechiesFilter[4];

Compute probabilities for all test images and all histogram models

time1 = AbsoluteTime[];
probs = AnalyzeOneImage[#, testOffset, db4, centroids, hist, 
              bandMap] &  /@  testData;
AbsoluteTime[] - time1

Visualize individual histogram classifications of test images

The graphics below illustrate the classification of each test image by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

results = 
        Map[VisualizeResults[#,  colors,  
              DisplayFunction -> Identity] &,  
          probs,  {2}];

gresults = Map[Last, results, {2}];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[Transpose[gresults]], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Visualize overall classifications of test images

resultsCombined = 
        Map[VisualizeResults[Times  @@ #,  colors,  
              DisplayFunction -> Identity] &,  probs];

gresultsCombined = 
        Map[Last, resultsCombined];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[gresultsCombined], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Summary of percent correct classification

By band (1 - HL1, 2 - LH1, 3 - HH1, 4 - HL2, 5 - LH2, 6 - HH3)

correctbyband = 
        Table[Map[First, results, {2}][[j, i, j]], {j, 1, 
            Length[testData]}, {i, 1, Length[bandMap]}];
BarChart[Sequence  @@  correctbyband, BarStyle -> colors, 
        BarEdgeStyle -> colors,  Frame -> True,  
        GridLines -> {None, Automatic}, 
        ImageSize -> 400];

Overall bands and overall correct classification percentage

correctoverall = 
        Table[Map[First, resultsCombined][[i, i]], {i, 1, 
            Length[testData]}];
BarChart[correctoverall,  BarStyle -> colors, 
        BarEdgeStyle -> colors, Frame -> True,  
        ImageSize -> 400];
Mean[correctoverall]

Analysis and testing #4 (16 clusters per band)

Level of quantization

Select level of quantization (1, 2, 3, 4, 5, 6)

vqlevel = 4;

Pick corresponding VQ codebook and histograms

centroids = centroidsAll[[vqlevel]];
hist = histAll[[vqlevel]];

Visualize centroids by band

The graphics below illustrate the centroids by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

VisualizeCentroids[#, ImageSize -> 500] &  /@  
        centroids;

Visualize histograms

The graphics below illustrate the histogram over the VQ codebooks by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

colors = {Red, Green, Blue, Orange};

BarChart[Sequence  @@  #, BarStyle -> colors, 
            BarEdgeStyle -> colors, Frame -> True, 
            ImageSize -> 500] &  /@  hist;

Visualize test images

Define test image data

testPos1 = {1, 1};
testPos2 = {160, 320};
testOffset = {4, 4};

Visualize test image data

testData = TakeMatrix[#, testPos1, testPos2] &  /@  
          texImages;
testVis = 
BlockMatrix[
          Partition[testData, 2]];
ShowImage[testVis];

Compute all test image probabilities

Define filter (same as used during training)

db4 = DaubechiesFilter[4];

Compute probabilities for all test images and all histogram models

time1 = AbsoluteTime[];
probs = AnalyzeOneImage[#, testOffset, db4, centroids, hist, 
              bandMap] &  /@  testData;
AbsoluteTime[] - time1

Visualize individual histogram classifications of test images

The graphics below illustrate the classification of each test image by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

results = 
        Map[VisualizeResults[#,  colors,  
              DisplayFunction -> Identity] &,  
          probs,  {2}];

gresults = Map[Last, results, {2}];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[Transpose[gresults]], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Visualize overall classifications of test images

resultsCombined = 
        Map[VisualizeResults[Times  @@ #,  colors,  
              DisplayFunction -> Identity] &,  probs];

gresultsCombined = 
        Map[Last, resultsCombined];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[gresultsCombined], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Summary of percent correct classification

By band (1 - HL1, 2 - LH1, 3 - HH1, 4 - HL2, 5 - LH2, 6 - HH3)

correctbyband = 
        Table[Map[First, results, {2}][[j, i, j]], {j, 1, 
            Length[testData]}, {i, 1, Length[bandMap]}];
BarChart[Sequence  @@  correctbyband, BarStyle -> colors, 
        BarEdgeStyle -> colors,  Frame -> True,  
        GridLines -> {None, Automatic}, 
        ImageSize -> 400];

Overall bands and overall correct classification percentage

correctoverall = 
        Table[Map[First, resultsCombined][[i, i]], {i, 1, 
            Length[testData]}];
BarChart[correctoverall,  BarStyle -> colors, 
        BarEdgeStyle -> colors, Frame -> True,  
        ImageSize -> 400];
Mean[correctoverall]

Analysis and testing #5 (32 clusters per band)

Level of quantization

Select level of quantization (1, 2, 3, 4, 5, 6)

vqlevel = 5;

Pick corresponding VQ codebook and histograms

centroids = centroidsAll[[vqlevel]];
hist = histAll[[vqlevel]];

Visualize centroids by band

The graphics below illustrate the centroids by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

VisualizeCentroids[#, ImageSize -> 500] &  /@  
        centroids;

Visualize histograms

The graphics below illustrate the histogram over the VQ codebooks by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

colors = {Red, Green, Blue, Orange};

BarChart[Sequence  @@  #, BarStyle -> colors, 
            BarEdgeStyle -> colors, Frame -> True, 
            ImageSize -> 500] &  /@  hist;

Visualize test images

Define test image data

testPos1 = {1, 1};
testPos2 = {160, 320};
testOffset = {4, 4};

Visualize test image data

testData = TakeMatrix[#, testPos1, testPos2] &  /@  
          texImages;
testVis = 
BlockMatrix[
          Partition[testData, 2]];
ShowImage[testVis];

Compute all test image probabilities

Define filter (same as used during training)

db4 = DaubechiesFilter[4];

Compute probabilities for all test images and all histogram models

time1 = AbsoluteTime[];
probs = AnalyzeOneImage[#, testOffset, db4, centroids, hist, 
              bandMap] &  /@  testData;
AbsoluteTime[] - time1

Visualize individual histogram classifications of test images

The graphics below illustrate the classification of each test image by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

results = 
        Map[VisualizeResults[#,  colors,  
              DisplayFunction -> Identity] &,  
          probs,  {2}];

gresults = Map[Last, results, {2}];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[Transpose[gresults]], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Visualize overall classifications of test images

resultsCombined = 
        Map[VisualizeResults[Times  @@ #,  colors,  
              DisplayFunction -> Identity] &,  probs];

gresultsCombined = 
        Map[Last, resultsCombined];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[gresultsCombined], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Summary of percent correct classification

By band (1 - HL1, 2 - LH1, 3 - HH1, 4 - HL2, 5 - LH2, 6 - HH3)

correctbyband = 
        Table[Map[First, results, {2}][[j, i, j]], {j, 1, 
            Length[testData]}, {i, 1, Length[bandMap]}];
BarChart[Sequence  @@  correctbyband, BarStyle -> colors, 
        BarEdgeStyle -> colors,  Frame -> True,  
        GridLines -> {None, Automatic}, 
        ImageSize -> 400];

Overall bands and overall correct classification percentage

correctoverall = 
        Table[Map[First, resultsCombined][[i, i]], {i, 1, 
            Length[testData]}];
BarChart[correctoverall,  BarStyle -> colors, 
        BarEdgeStyle -> colors, Frame -> True,  
        ImageSize -> 400];
Mean[correctoverall]

Analysis and testing #6 (64 clusters per band)

Level of quantization

Select level of quantization (1, 2, 3, 4, 5, 6)

vqlevel = 6;

Pick corresponding VQ codebook and histograms

centroids = centroidsAll[[vqlevel]];
hist = histAll[[vqlevel]];

Visualize centroids by band

The graphics below illustrate the centroids by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

VisualizeCentroids[#, ImageSize -> 500] &  /@  
        centroids;

Visualize histograms

The graphics below illustrate the histogram over the VQ codebooks by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

colors = {Red, Green, Blue, Orange};

BarChart[Sequence  @@  #, BarStyle -> colors, 
            BarEdgeStyle -> colors, Frame -> True, 
            ImageSize -> 500] &  /@  hist;

Visualize test images

Define test image data

testPos1 = {1, 1};
testPos2 = {160, 320};
testOffset = {4, 4};

Visualize test image data

testData = TakeMatrix[#, testPos1, testPos2] &  /@  
          texImages;
testVis = 
BlockMatrix[
          Partition[testData, 2]];
ShowImage[testVis];

Compute all test image probabilities

Define filter (same as used during training)

db4 = DaubechiesFilter[4];

Compute probabilities for all test images and all histogram models

time1 = AbsoluteTime[];
probs = AnalyzeOneImage[#, testOffset, db4, centroids, hist, 
              bandMap] &  /@  testData;
AbsoluteTime[] - time1

Visualize individual histogram classifications of test images

The graphics below illustrate the classification of each test image by band (HL1, LH1, HH1, HL2, LH2, HH2) down the columns.

results = 
        Map[VisualizeResults[#,  colors,  
              DisplayFunction -> Identity] &,  
          probs,  {2}];

gresults = Map[Last, results, {2}];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[Transpose[gresults]], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Visualize overall classifications of test images

resultsCombined = 
        Map[VisualizeResults[Times  @@ #,  colors,  
              DisplayFunction -> Identity] &,  probs];

gresultsCombined = 
        Map[Last, resultsCombined];
gimages = ShowImage[#, 1, 255, 0, 
              DisplayFunction -> Identity] &  /@  
          testData;
Show[GraphicsArray[gimages], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction];
Show[GraphicsArray[gresultsCombined], ImageSize -> 640, 
        DisplayFunction -> $DisplayFunction, 
        GraphicsSpacing -> 0];

Summary of percent correct classification

By band (1 - HL1, 2 - LH1, 3 - HH1, 4 - HL2, 5 - LH2, 6 - HH3)

correctbyband = 
        Table[Map[First, results, {2}][[j, i, j]], {j, 1, 
            Length[testData]}, {i, 1, Length[bandMap]}];
BarChart[Sequence  @@  correctbyband, BarStyle -> colors, 
        BarEdgeStyle -> colors,  Frame -> True,  
        GridLines -> {None, Automatic}, 
        ImageSize -> 400];

Overall bands and overall correct classification percentage

correctoverall = 
        Table[Map[First, resultsCombined][[i, i]], {i, 1, 
            Length[testData]}];
BarChart[correctoverall,  BarStyle -> colors, 
        BarEdgeStyle -> colors, Frame -> True,  
        ImageSize -> 400];
Mean[correctoverall]