vector_aggregation
Class VladAggregatorWithFiltering

java.lang.Object
  extended by vector_aggregation.AbstractFeatureAggregator
      extended by vector_aggregation.VladAggregatorWithFiltering

public class VladAggregatorWithFiltering
extends AbstractFeatureAggregator

This is an experimental version of the VladAggregator class which implements 3 methods for feature filtering based on feature-vocabulary relation. The produced VLAD vectors should be power and L2 normalized afterwards.

Author:
Eleftherios Spyromitros-Xioufis

Nested Class Summary
static class VladAggregatorWithFiltering.FilteringMethod
          The alternative methods for feature filtering based on feature-vocabulary relation.
 
Field Summary
private  long featuresRejected
          Counts the total number of rejected features.
private  VladAggregatorWithFiltering.FilteringMethod filteringMethod
          The VladAggregatorWithFiltering.FilteringMethod to be used.
private  double numStds
          The a parameter of the std method.
private  double percentage
          The percentage of features to be retained.
static double[] percentages
          Percentages for which thresholds have been pre-calculated for the std and ratio methods.
private  double ratio
          The b parameter of the ratio filtering method.
private  double[] thresholdsDist
          Thresholds for the dist method.
static double[] thresholdsRatio
          Thresholds for the ratio method corresponding to the percentages above.
static double[] thresholdsStd
          Thresholds for the std method corresponding to the percentages above.
 
Fields inherited from class vector_aggregation.AbstractFeatureAggregator
codebook, descriptorLength, numCentroids, vectorLength
 
Constructor Summary
VladAggregatorWithFiltering(double[][] codebook, VladAggregatorWithFiltering.FilteringMethod filteringMethod, double percentage)
          Contructor.
 
Method Summary
 double[] aggregateInternal(java.util.ArrayList<double[]> descriptors)
          Takes as input an ArrayList of double arrays which contains the set of local features for an image.
 double[] aggregateInternal(double[][] features)
          Takes as input 2-dimensional double array which contains the set of local features for an image.
static void computeDistributionOfDistances(java.lang.String featuresFolder, int numFiles, java.lang.String featureType, java.lang.String featureNormalization, int featureLength, java.lang.String codebookFile, int numCentroids)
          This method takes as input a folder containing .surf or .sift files extracted from a set of images, quantizes all the descriptors against a given codebooks and writes in a file the distribution of distances in each centroid.
protected  int computeNearestCentroidRejectDistribution(double[] feature)
          Returns the index of the centroid which is closer to the given feature or -1 if the feature is rejected.
protected  int computeNearestCentroidRejectRatio(double[] feature)
          Returns the index of the centroid which is closer to the given feature or -1 if the feature is rejected.
protected  int computeNearestCentroidRejectStd(double[] feature)
          Returns the index of the centroid which is closer to the given feature or -1 if the feature is rejected.
 long getDescriptorsRejected()
           
 int getVectorLength()
          Should compute and return the length of the generated vector.
static void main(java.lang.String[] args)
          This method can be used for calculating the percentage values in the distribution method.
 void setPercentiles(java.lang.String fileName)
          This method sets the percentile values used by the dist methdod.
 
Methods inherited from class vector_aggregation.AbstractFeatureAggregator
aggregate, aggregate, computeKNearestCentroids, computeNearestCentroid, computeNearestCentroidIndexAndDistance, getDescriptorLength, getNumCentroids, readCodebookFile, setDescriptorLength, setNumCentroids
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filteringMethod

private VladAggregatorWithFiltering.FilteringMethod filteringMethod
The VladAggregatorWithFiltering.FilteringMethod to be used.


numStds

private double numStds
The a parameter of the std method.


ratio

private double ratio
The b parameter of the ratio filtering method.


percentage

private double percentage
The percentage of features to be retained.


percentages

public static final double[] percentages
Percentages for which thresholds have been pre-calculated for the std and ratio methods.


thresholdsStd

public static final double[] thresholdsStd
Thresholds for the std method corresponding to the percentages above.


thresholdsRatio

public static final double[] thresholdsRatio
Thresholds for the ratio method corresponding to the percentages above.


thresholdsDist

private double[] thresholdsDist
Thresholds for the dist method. A different threshold for each centroid, spedified by the setPercentiles(String) method.


featuresRejected

private long featuresRejected
Counts the total number of rejected features.

Constructor Detail

VladAggregatorWithFiltering

public VladAggregatorWithFiltering(double[][] codebook,
                                   VladAggregatorWithFiltering.FilteringMethod filteringMethod,
                                   double percentage)
                            throws java.lang.Exception
Contructor.

Parameters:
codebook -
filteringMethod -
percentage -
Throws:
java.lang.Exception
Method Detail

getDescriptorsRejected

public long getDescriptorsRejected()
Returns:

aggregateInternal

public double[] aggregateInternal(double[][] features)
                           throws java.lang.Exception
Takes as input 2-dimensional double array which contains the set of local features for an image. Returns the VLAD vector representation of the image using the codebook supplied in the constructor.

Specified by:
aggregateInternal in class AbstractFeatureAggregator
Returns:
Throws:
java.lang.Exception

aggregateInternal

public double[] aggregateInternal(java.util.ArrayList<double[]> descriptors)
                           throws java.lang.Exception
Takes as input an ArrayList of double arrays which contains the set of local features for an image. Returns the VLAD vector representation of the image using the codebook supplied in the constructor.

Specified by:
aggregateInternal in class AbstractFeatureAggregator
Returns:
Throws:
java.lang.Exception

computeNearestCentroidRejectStd

protected int computeNearestCentroidRejectStd(double[] feature)
Returns the index of the centroid which is closer to the given feature or -1 if the feature is rejected. If the distance to the nearest centroid is not significantly smaller than the mean distance accross all centroids, then reject the feature. To measure the magniture of the difference from mean we use the number of stds from the mean value.

Parameters:
feature -
Returns:

computeNearestCentroidRejectRatio

protected int computeNearestCentroidRejectRatio(double[] feature)
Returns the index of the centroid which is closer to the given feature or -1 if the feature is rejected.

Parameters:
feature -
Returns:

computeNearestCentroidRejectDistribution

protected int computeNearestCentroidRejectDistribution(double[] feature)
Returns the index of the centroid which is closer to the given feature or -1 if the feature is rejected.

Parameters:
feature -
Returns:

getVectorLength

public int getVectorLength()
Description copied from class: AbstractFeatureAggregator
Should compute and return the length of the generated vector.

Specified by:
getVectorLength in class AbstractFeatureAggregator
Returns:

setPercentiles

public void setPercentiles(java.lang.String fileName)
                    throws java.io.IOException
This method sets the percentile values used by the dist methdod. The percentile values are stored in a file. Each column represents a different percentile and each row a different centroid. The first row contains the percentile for which we have calculated the values.

Parameters:
fileName -
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
This method can be used for calculating the percentage values in the distribution method.

Parameters:
args - [0] Full path to the folder containing the local features (use backslashes).
Throws:
java.lang.Exception

computeDistributionOfDistances

public static void computeDistributionOfDistances(java.lang.String featuresFolder,
                                                  int numFiles,
                                                  java.lang.String featureType,
                                                  java.lang.String featureNormalization,
                                                  int featureLength,
                                                  java.lang.String codebookFile,
                                                  int numCentroids)
                                           throws java.lang.Exception
This method takes as input a folder containing .surf or .sift files extracted from a set of images, quantizes all the descriptors against a given codebooks and writes in a file the distribution of distances in each centroid.

Parameters:
featuresFolder -
numFiles -
featureType -
featureNormalization -
featureLength -
codebookFile -
numCentroids -
Throws:
java.lang.Exception