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 |
---|
CityLandscapeTree(String cat1,
String cat2)
Default constructor that takes the two categories
to classifier between.
|
CityLandscapeTree(String cat1,
String cat2,
InputStream trainingSet,
int trainingSetSize)
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 |
---|---|
String |
classifyImage(FImage image,
int k)
Classifies the given image.
|
double[][] |
loadTrainingSet(InputStream is,
int vecSize)
Loads a training set of a given size from an input stream
|
static void |
main(String[] args)
Given an image filename, it will classify it.
|
public CityLandscapeTree(String cat1, String cat2)
cat1
- The first categorycat2
- The second categorypublic CityLandscapeTree(String cat1, String cat2, InputStream trainingSet, int trainingSetSize)
cat1
- The first classification categorycat2
- The second classification categorytrainingSet
- The training settrainingSetSize
- The size of the training setpublic String classifyImage(FImage image, int k)
image
- The image to classifyk
- The number of nearest neighbours to interrogatepublic double[][] loadTrainingSet(InputStream is, int vecSize) throws IOException
is
- The input stream to read the training set fromvecSize
- The size of the training setIOException
- if the input stream could not be fully read