public class CityLandscapeTree extends Object
This class provides classification of objects. The idea in the classifier is to classfy images between landscape images and cityscape images. Could also be used as a natural vs. non-natural classifier as the technique used is based on edge-direction coherence vectors (i.e. looking for strong lines). The training set (src/main/resources/CityLS10000.2.no-decimal) provides 5000 examples of edge direction coherence vectors for both city scape and landscape (the original images were crawled from Flickr based on appropriate tags). Internally the classifier uses the nearest neighbour to determine the class of the query.
To use, do something like this:
CityLandscapeTree clt = new CityLandscapeTree( "city", "landscape", getClass().getResourceAsStream( "/CityLS10000.2.no-decimal" ), 10000 ); String clazz = clt.classifyImage( ImageUtilities.readF( new File("myImage.jpg") ), 1 );
A main method is supplied for the tool which will take an image filename and classify the image as city or landscape.
|Constructor and Description|
Default constructor that takes the two categories to classifier between.
Constructor that takes the two categories to classify between, an input stream that points to a training set file and the size of that training set.
|Modifier and Type||Method and Description|
Classifies the given image.
Loads a training set of a given size from an input stream
Given an image filename, it will classify it.
public CityLandscapeTree(String cat1, String cat2)
cat1- The first category
cat2- The second category
public CityLandscapeTree(String cat1, String cat2, InputStream trainingSet, int trainingSetSize)
cat1- The first classification category
cat2- The second classification category
trainingSet- The training set
trainingSetSize- The size of the training set
public String classifyImage(FImage image, int k)
image- The image to classify
k- The number of nearest neighbours to interrogate
public double loadTrainingSet(InputStream is, int vecSize) throws IOException
is- The input stream to read the training set from
vecSize- The size of the training set
IOException- if the input stream could not be fully read