public int classify ( T image ) { if ( numNeighbors == 0 ) throw new IllegalArgumentException ( "Must specify number of neighbors!" ) ; // compute all the features inside the image describe . process ( image ) ; // find which word the feature matches and construct a frequency histogram featureToHistogram . reset ( ) ; List < Desc > imageFeatures = describe . getDescriptions ( ) ; for ( int i = 0 ; i < imageFeatures . size ( ) ; i ++ ) { Desc d = imageFeatures . get ( i ) ; featureToHistogram . addFeature ( d ) ; } featureToHistogram . process ( ) ; temp . histogram = featureToHistogram . getHistogram ( ) ; // Find the N most similar image histograms resultsNN . reset ( ) ; search . findNearest ( temp , - 1 , numNeighbors , resultsNN ) ; // Find the most common scene among those neighbors Arrays . fill ( scenes , 0 ) ; for ( int i = 0 ; i < resultsNN . size ; i ++ ) { NnData < HistogramScene > data = resultsNN . get ( i ) ; HistogramScene n = data . point ; // scenes[n.type]++; scenes [ n . type ] += 1.0 / ( data . distance + 0.005 ) ; // todo // scenes[n.type] += 1.0/(Math.sqrt(data.distance)+0.005); // todo } // pick the scene with the highest frequency int bestIndex = 0 ; double bestCount = 0 ; for ( int i = 0 ; i < scenes . length ; i ++ ) { if ( scenes [ i ] > bestCount ) { bestCount = scenes [ i ] ; bestIndex = i ; } } return bestIndex ; }
Finds the scene which most resembles the provided image