public double [ ] transformToVector ( ) throws Exception { if ( vectorLength > vladAggregator . getVectorLength ( ) || vectorLength <= 0 ) { throw new Exception ( "Vector length should be between 1 and " + vladAggregator . getVectorLength ( ) ) ; } // the local features are extracted double [ ] [ ] features ; if ( image == null ) { // first the image is read if the image field is null try { // first try reading with the default class image = ImageIO . read ( new File ( imageFolder + imageFilename ) ) ; } catch ( IllegalArgumentException e ) { // this exception is probably thrown because of a greyscale jpeg image System . out . println ( "Exception: " + e . getMessage ( ) + " | Image: " + imageFilename ) ; // retry with the modified class image = ImageIOGreyScale . read ( new File ( imageFolder + imageFilename ) ) ; } } // next the image is scaled ImageScaling scale = new ImageScaling ( maxImageSizeInPixels ) ; try { image = scale . maxPixelsScaling ( image ) ; } catch ( Exception e ) { throw new Exception ( "Exception thrown when scaling the image!\n" + e . getMessage ( ) ) ; } // next the local features are extracted features = featureExtractor . extractFeatures ( image ) ; // next the features are aggregated double [ ] vladVector = vladAggregator . aggregate ( features ) ; if ( vladVector . length == vectorLength ) { // no projection is needed return vladVector ; } else { // pca projection is applied double [ ] projected = pcaProjector . sampleToEigenSpace ( vladVector ) ; return projected ; } }
Transforms the image into a vector and returns the result .