我阅读了有关 OpenIMAJ 的教程并从该教程中获得了以下代码。根据代码,我得到了图像的集群中心。但从那时起,我不知道如何使用这些值来比较 2 张图像。这是代码。我已经添加了文档中的注释,因此您可以了解一下。
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
}
在为图像运行上述代码后,我得到了以下结果。
Image 1:
[95.99463, 3.6134863, 2.641686]
[32.080914, 14.114657, -48.14841]
在另一张图片上运行上面的代码后,我得到了以下信息
Image 2:
[32.11119, 13.966739, -47.994236]
[95.64963, 3.9856236, 2.9136417]
通过使用这些值,我如何比较两张图像。我对如何比较图像没有任何想法。请帮我。提前致谢。