0

I read a tutorial on OpenIMAJ & got the following code from that tutorial. According to the code, I get the center of clusters for an image. But from that point onward I don't know how to use these values in order to compare 2 images. This is the code. I have added the comments as it was in the documentation, so you can get an idea.

 public static void main(String[] args) throws IOException  
  {
      final String input_1Str ="/compareimage/clip6.jpg";

    MBFImage input = ImageUtilities.readMBF(objectRecognition.class.getResourceAsStream(input_1Str));
    input = ColourSpace.convert(input, ColourSpace.CIE_Lab); //apply a colour-space transform to the image
    FloatKMeans cluster = FloatKMeans.createExact(2); //construct the K-Means algorithm. The parameter (2) is the number of clusters or classes we wish the algorithm to generate
    FloatKMeans.createKDTreeEnsemble(2);
    float[][] imageData = input.getPixelVectorNative(new float[input.getWidth() * input.getHeight()][3]); //The FloatKMeans algorithm takes its input as an array of floating point vectors (float[][]). We can flatten the pixels of an image into the required form using the getPixelVectorNative() method
    FloatCentroidsResult result = cluster.cluster(imageData);

    float[][] centroids = result.centroids; //The K-Means algorithm can then be run to group all the pixels into the requested number of classes
    for (float[] fs : centroids) {
      System.out.println(Arrays.toString(fs));  //Each class or cluster produced by the K-Means algorithm has an index, starting from 0. Each class is represented by its centroid. Running it prints the (L, a, b) coordinates of each of the classes
}

After running the above code for an image I got the following result.

Image 1:
[95.99463, 3.6134863, 2.641686]
[32.080914, 14.114657, -48.14841]

After running the above code on another image gives me the following

Image 2:
[32.11119, 13.966739, -47.994236]
[95.64963, 3.9856236, 2.9136417]

By using these values how can I compare the 2 images. I don't have any ideas on how to compare the images. Please help me. Thanks in advance.

Tharu
  • 353
  • 1
  • 2
  • 11
  • I'm not entirely sure your question makes sense. The code you've posted is for a tutorial on colour clustering - I'm not sure that you'd want to use that for image comparison as it would be really crude. You should take a look at http://openimaj.github.io/openimaj/tutorial/global-image-features.html and http://openimaj.github.io/openimaj/tutorial/sift-and-feature-matching.html for better ways of comparing images. – Jon Jul 22 '15 at 13:40
  • @Jon According to the above code it says that it prints (L, a, b) coordinates of each of the classes. Do you have any idea on what does ( L, a, b) stands for? – Tharu Jul 22 '15 at 14:00
  • Lab is a colour space (https://en.wikipedia.org/wiki/Lab_color_space). L is the lightness, and a and b are the opponent colour dimensions. – Jon Jul 23 '15 at 08:39

0 Answers0