Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

image comparison in java [closed]

I'm working on my college project, in which I am required to do fingerprint comparison. This can be done by comparing two image and matching their pixel similarity (as per my finding).

Is there any API/library/SDK or anything available in Java, for comparing two images and getting the percentage match between them?


2 Answers

Check out the OpenCV library. You can find there exactly what you need. Take a look here for example of how to compare images.

like image 118
Lior Ohana Avatar answered Apr 02 '26 09:04

Lior Ohana


Would something like this work for you. The commented lines are likely not quite right.

int numberOfPixels = 0;
float runningTotal = 0;    
for (int i = 0; i < image.width; i++)
{
    for (int j = 0; j < image.height; j++)
    {
        //Color a = image1.getPixel(i, j);
        //Color b = image2.getPixel(i, j);

        float differenceRed = abs(a.red() - b.red()) / 255;
        float differenceGreen = abs(a.green() - b.green()) / 255;
        float differenceBlue = abs(a.blue() - b.blue()) / 255;

        float differenceForThisPixel = (differenceRed + differenceGreen + differenceBlue) / 3;
        runningTotal += differenceForThisPixel;
        numberOfPixels++;

    }
}
averageDifference = (runningTotal / numberOfPixels);
like image 22
James Webster Avatar answered Apr 02 '26 08:04

James Webster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!