stereodisk
Class StereoDiskAnalyzer

java.lang.Object
  |
  +--stereodisk.StereoDiskAnalyzer
Direct Known Subclasses:
StereoCupRimClassifier, StereoDiskANNTester, StereoDiskGroundTruthAnalyzer, StereoDiskIxConverter

public class StereoDiskAnalyzer
extends java.lang.Object

Stereo disk photograph analysis. New version: uses a directory that has a separate stack (multi TIFF file) for each future for all stereo pairs (starting with fts-) and the ground truth, starting with gt. Algorithm:

 get  list of all feature
      collect = null
      for all features
               for all features
                      load current feature and all features in collect for odd images into kNN
                      determine estimation of even images with kNN
                      determine best accuracy
               add feature with best accuracy to collect

 Old version (remains in this file for reference):
 Uses a stack that contains ground truth and all features image-wise.
 The names are lost here.

 Copyright (c) 1999-2004, Michael Abramoff. All rights reserved.


Field Summary
protected static int height
           
protected static int PIXEL_SAMPLING
           
(package private) static float[][][] testing
          Obtain a training or test set (depending on train) as an MxN vector where N is number of features and M is the number of subsampled pixels in all images.
(package private) static float[][][] training
           
protected static int width
           
 
Constructor Summary
StereoDiskAnalyzer()
           
 
Method Summary
static float[][] analyzeProbabilities(float[][] ft, float[][] truths, int width, java.util.Vector featureNames)
          Determine the probabilities that a pixelfeature can differentiate between two classes for all classes and all features.
protected static java.lang.String buildString(java.lang.String[] ss)
           
protected static int[] createBalancedSampleBlock(float[] population, int n)
          Kreeer een block van n x,y coordinaten waarmee de kans zo hoog mogelijk is om 1:1:1 van de 3 classificaties te vangen.
protected static int[][] createBalancedSampleBlocks(float[][] groundtruths, int n)
          Create as many blocks of balanced pixel indices as there are images in images.
protected static int[] createSampleBlock(float[] population, int n)
          Create an unbalanced sample block.
protected static int[][] createSampleBlocks(float[][] groundtruths, int n)
          Create as many blocks of balanced pixel indices as there are images in images.
protected static float[][] imageFeaturePixels(int i, java.lang.String directory, java.lang.String[] names)
          Obtain all features names for a single image i.
static float[][] loadFeatures(java.lang.String directory, java.lang.String[] names, int[][] coords, boolean train)
           
protected static float[] loadFloatImage(java.lang.String directory, java.lang.String name, int i)
          Load the i'th image in name as a float[][].
protected static float[][] loadFloatImages(java.lang.String directory, java.lang.String name)
          Load the images in name (a mutli-image TIFF file) as a float[][].
static void main(java.lang.String[] args)
           
protected static int min(int[] v)
           
protected static float[][] pixelsToDataset(float[][][] samplePixels)
          samplePixels contains the pixel values for each sampled image for each feature (N).
protected static void plotProbs(float[][] p, java.util.Vector featureNames, java.lang.String directory, java.lang.String name)
          Plot the probabilities for each feature.
protected static float[][] sampleEvenImages(float[][] images)
          Subsample the even images from images and convert to a vector array (which is much smaller).
protected static float[][] sampleFeatureImagePixels(java.lang.String directory, java.lang.String[] names, boolean odd)
          Obtain half of all images for all features in names, and compact into a MxN vector, where N is the number of features and M is the number of subsampled pixels in all images.
protected static float[] sampleFeatureImagePixels(java.lang.String directory, java.lang.String name, boolean odd)
          Obtain half of all images for the feature in name, and compact into a Mx1 vector, where M is the number of subsampled pixels in all images.
protected static float[][] sampleImages(float[][] images, boolean odd)
          Sample the images either odd or even from images and convert to a vector array (which is much half the size).
protected static float[][] sampleOddImages(float[][] images)
          Sample the odd images from images and convert to a vector array (which is much smaller).
static void showAccuracies(Features dataset, float[] featureTruth, Features m, float[] mTruth, int n, int k)
          Print the accuracies for each feature used in knn search.
protected static float[][] subsample(float[][] set, int distance)
          Sample every distance elements from set.
protected static float[] subsample(float[] set, int distance)
          Sample every distance elements from set.
protected static float[][][] subset(float[][][] set, int[][] indices)
          Select the subset of pixels (indicated by indices), from set.
protected static float[][] subset(float[][] set, int[][] indices)
          Select the subset of pixels (indicated by indices), from set.
protected static float[][] testKNN(BIJknn knn, java.lang.String directory, java.lang.String[] names, java.lang.String gtname)
          Test a kNN classifier with a test set in names (the odd images), and the ground truth as classification vectors.
protected static BIJknn trainKNN(java.lang.String directory, java.lang.String[] names, java.lang.String gtname)
          Train a KNN classifier with the features in names as feature vectors, and the ground truth in gtname as classification vectors.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PIXEL_SAMPLING

protected static final int PIXEL_SAMPLING

width

protected static int width

height

protected static int height

testing

static float[][][] testing
Obtain a training or test set (depending on train) as an MxN vector where N is number of features and M is the number of subsampled pixels in all images. This method determines both training and test set with one call, the second call with train == false will return the previously loaded test set. If train = true, do the odd images only. if train = false, do the even images only.

training

static float[][][] training
Constructor Detail

StereoDiskAnalyzer

public StereoDiskAnalyzer()
Method Detail

main

public static void main(java.lang.String[] args)

trainKNN

protected static BIJknn trainKNN(java.lang.String directory,
                                 java.lang.String[] names,
                                 java.lang.String gtname)
                          throws java.lang.Exception
Train a KNN classifier with the features in names as feature vectors, and the ground truth in gtname as classification vectors. Initialize a kNN classifier with these features and classifications.
Returns:
the kNN classifier with the features in names and the classifications in gtname.

testKNN

protected static float[][] testKNN(BIJknn knn,
                                   java.lang.String directory,
                                   java.lang.String[] names,
                                   java.lang.String gtname)
Test a kNN classifier with a test set in names (the odd images), and the ground truth as classification vectors.
Returns:
a float[2][] with the first array containing the true classifications, and the second the kNN estimated classifications.

loadFeatures

public static float[][] loadFeatures(java.lang.String directory,
                                     java.lang.String[] names,
                                     int[][] coords,
                                     boolean train)
                              throws java.lang.Exception

imageFeaturePixels

protected static float[][] imageFeaturePixels(int i,
                                              java.lang.String directory,
                                              java.lang.String[] names)
Obtain all features names for a single image i. Becuase the images are spread over all feature multi-image TIFF files, this collects the features of the i'th image in one matrix MxN vector, where N is the number of features and M is the number of pixels in an image.
Parameters:
i - the index of the desired image.
names - the names of all feature multi-image TIFF files.
Returns:
a MxN matrix with the N-dimensional feature vectors for all pixels.

sampleFeatureImagePixels

protected static float[][] sampleFeatureImagePixels(java.lang.String directory,
                                                    java.lang.String[] names,
                                                    boolean odd)
Obtain half of all images for all features in names, and compact into a MxN vector, where N is the number of features and M is the number of subsampled pixels in all images. If odd = true, do the odd images only. if odd = false, do the even images only.
Parameters:
names - the names of all feature image stack files.
Returns:
a MxN vector with the N-dimensional feature vectors for all pixels.

sampleFeatureImagePixels

protected static float[] sampleFeatureImagePixels(java.lang.String directory,
                                                  java.lang.String name,
                                                  boolean odd)
Obtain half of all images for the feature in name, and compact into a Mx1 vector, where M is the number of subsampled pixels in all images. If odd = true, do the odd images only. if odd = false, do the even images only.
Parameters:
name - the name of the feature image stack file.
Returns:
a Mx1 vector with the features for all pixels.

loadFloatImages

protected static float[][] loadFloatImages(java.lang.String directory,
                                           java.lang.String name)
Load the images in name (a mutli-image TIFF file) as a float[][].
Parameters:
directory, - the directory to get it from.
name, - the name of the multi-image TIFF file.

loadFloatImage

protected static float[] loadFloatImage(java.lang.String directory,
                                        java.lang.String name,
                                        int i)
Load the i'th image in name as a float[][].
Parameters:
directory, - the directory to get it from.
name, - the name of the multi-image TIFF file.
i - the index of the image within the multi-image file.

pixelsToDataset

protected static float[][] pixelsToDataset(float[][][] samplePixels)
samplePixels contains the pixel values for each sampled image for each feature (N). Sort of combined transpose and flatten. Convert into a feature vector for each pixel.
Returns:
the appropriately dimensioned dataset (MxN).

sampleImages

protected static float[][] sampleImages(float[][] images,
                                        boolean odd)
Sample the images either odd or even from images and convert to a vector array (which is much half the size).
Returns:
with the pixels in each sampled image as a float[][]

sampleOddImages

protected static float[][] sampleOddImages(float[][] images)
Sample the odd images from images and convert to a vector array (which is much smaller).
Returns:
with the pixels in each sampled image as a float[][]

sampleEvenImages

protected static float[][] sampleEvenImages(float[][] images)
Subsample the even images from images and convert to a vector array (which is much smaller).
Returns:
with the pixels in each sampled image as a float[][]

subsample

protected static float[][] subsample(float[][] set,
                                     int distance)
Sample every distance elements from set.
Returns:
the subsampled set.

subsample

protected static float[] subsample(float[] set,
                                   int distance)
Sample every distance elements from set.
Returns:
the subsampled set.

analyzeProbabilities

public static float[][] analyzeProbabilities(float[][] ft,
                                             float[][] truths,
                                             int width,
                                             java.util.Vector featureNames)
Determine the probabilities that a pixelfeature can differentiate between two classes for all classes and all features. The truths, images in which only the pixel that have that true value are != 0, are used as masks.
Parameters:
ft - a float [][] matrix with images (row vectors).
truths - a float[][] matrix of column vector images for each class. A pixel is that class if the corresponding truth element is !0
Returns:
a float[][], with a p value for each feature and between all classes.

plotProbs

protected static void plotProbs(float[][] p,
                                java.util.Vector featureNames,
                                java.lang.String directory,
                                java.lang.String name)
Plot the probabilities for each feature.

showAccuracies

public static void showAccuracies(Features dataset,
                                  float[] featureTruth,
                                  Features m,
                                  float[] mTruth,
                                  int n,
                                  int k)
Print the accuracies for each feature used in knn search. Features contains a data space for knn, and m contains the features that need to be classified. The average accuracy of the resulting classification vector is determined and shown. The features and m need to be organized in the same way, i.e. features[x][j] and m[y][j] refer to a feature of the same type, j.
Parameters:
features - the MxN matrix of N-dimensional features
featureTruth - a 1xM vector of the true classification for each element in data, 0 <= truth[i] <= n.
m - a PxQ matrix of Q-dimensional features that need to be classified, with Q <= N.
mTruth - a 1xP vector of the true classification for each element in m, 0 <= truth[i] <= n.
featureNames - the name of each j'th feature in features (and m).
n - the number of different classes in truth.
k - the number of neighbors to use for classification
Returns:
the kNN classification for all elements in features.

buildString

protected static java.lang.String buildString(java.lang.String[] ss)

subset

protected static float[][] subset(float[][] set,
                                  int[][] indices)
Select the subset of pixels (indicated by indices), from set. set is a matrix, each pixel in the matrix is indexed by indices, corresponding pixels should be taken
Returns:
the subsampled set.

subset

protected static float[][][] subset(float[][][] set,
                                    int[][] indices)
Select the subset of pixels (indicated by indices), from set. set is an array of matrices each pixel in each matrix is indexed by indices, corresponding pixels should be taken from each array element.
Returns:
the subsampled set.

createBalancedSampleBlock

protected static int[] createBalancedSampleBlock(float[] population,
                                                 int n)
Kreeer een block van n x,y coordinaten waarmee de kans zo hoog mogelijk is om 1:1:1 van de 3 classificaties te vangen. About 200000 pixels are class 0, 50000 class 1 and 25000 class 2. Als most 0 are at the edges. Still you want the same numbers of feature vectors for each class. For 50 images of 250000 pixels each, you have 12.5 million pixels. Als je er 12500 van wil hebben is dat 1:1000 pixels. Dus per plaatje 250 pixels van ieder. Je kan ook een random block creeeren die voor een plaatje 1:1:1 aantallen pixels samplet, en dan dat gebruiken voor allemaal.
Parameters:
population - the population from which you want a sample.
n - number of samples desired.
Returns:
the x,y coordinates

createSampleBlock

protected static int[] createSampleBlock(float[] population,
                                         int n)
Create an unbalanced sample block. The number of samples for each class is equal to the proportion of the occurence of that class in population.
Returns:
an int[] with the x ([0]), and (y[1]) coordinates

createSampleBlocks

protected static int[][] createSampleBlocks(float[][] groundtruths,
                                            int n)
Create as many blocks of balanced pixel indices as there are images in images. You want the same numbers of feature vectors for each class. For 50 images of 250000 pixels each, you have 12.5 million pixels. Als je er 12500 van wil hebben is dat 1:1000 pixels. Dus per plaatje 250 pixels van ieder.
Parameters:
groundtruth - the array of images containing the correct classes for each pixels.
Returns:
the x,y coordinates

createBalancedSampleBlocks

protected static int[][] createBalancedSampleBlocks(float[][] groundtruths,
                                                    int n)
Create as many blocks of balanced pixel indices as there are images in images. You want the same numbers of feature vectors for each class. For 50 images of 250000 pixels each, you have 12.5 million pixels. Als je er 12500 van wil hebben is dat 1:1000 pixels. Dus per plaatje 250 pixels van ieder.
Parameters:
groundtruth - the array of images containing the correct classes for each pixels.
Returns:
the x,y coordinates

min

protected static int min(int[] v)