Tuesday, June 9, 2009

How to compare two images, check two image are same or not

You can compare two images using imagemagick.
You can download imagemagick from here. Version must be greater than 6.0. (like ImageMagick-6.4.3-Q16). Suppose you install in "C:\Program Files " folder then you can run command from this location C:\Program Files\ImageMagick-6.4.3-Q16>

After successfully installation you can use this below command
C:\Program Files\ImageMagick-6.4.3-Q16>compare -metric AE 5001.MAIN.jpg 5002.MAIN.jpg difference.jpg
if it returns value 0 means both images are same.

Even you can use -verbose attribute with this command to get more output.
C:\Program Files\ImageMagick-6.4.3-Q16>compare -verbose -metric AE 5001.MAIN.jpg 5002.MAIN.jpg difference.jpg

You can check this command with two different images, two same images.

There are some more command
C:\Program Files\ImageMagick-6.4.3-Q16> compare -compose src rose.jpg reconstruct.jpg difference.png
C:\Program Files\ImageMagick-6.4.3-Q16> compare -verbose -metric mae rose.jpg reconstruct.jpg difference.png
C:\Program Files\ImageMagick-6.4.3-Q16> compare -channel red -metric PSNR rose.jpg reconstruct.jpg difference.png

You can get more info from these link
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/

29 comments:

  1. How can I use this command using java. Actually I want image comparion using java code. This is my project requirement. Need your help.

    ReplyDelete
  2. I use this imagemgaick tools with java and got it workes fine. Thanks to give such useful information is very easy way.

    Thanks.

    ReplyDelete
  3. How did you use this command in Java. Is that possible to use in web based application and where to have the ImageMagick-6.5.3-7.i386.rpm in that case and how to call in jsp or servlet?

    ReplyDelete
  4. Hi Raf,

    Yes, you can use ImageMagick command in java and servlet very easily. Please visit my this blog (http://binodjava.blogspot.com/2009/05/how-to-use-runtimegetruntimeexec-how-to.html) for how to use any command in java. In that blog, instead of
    command.add("cmd.exe");
    command.add("/c");
    command.add("copy");
    command.add(sourceFile);
    command.add(destFile);

    You have to use

    command.add("C:\\Program Files\\ImageMagick-6.4.3-Q16\\compare.exe");
    command.add("-metric AE ");
    command.add(" 5001.MAIN.jpg ");
    command.add(" 5002.MAIN.jpg ");
    command.add(" difference.jpg");

    Try yourself, if not work I will give complete code on how to compare image in java using imageMagick.

    Regards,

    Binod Suman
    http://binodsuman.blogspot.com

    ReplyDelete
  5. can u please send me the java code to compare

    ReplyDelete
  6. Hi Binod,

    I tried to create a code to execute convert command to annotate the image with some text and compress it but, the destination file does not get created, can you please provide me your mail id, so, i can send you my code, as i am not able to copy it to this comment. Please help.

    ReplyDelete
  7. hey if possible can u pls send me the code at ayushi.gupta2@gmail.com

    ReplyDelete
  8. Thanks Binod.. I tried it but was unsuccessful van you plz give me the code.

    vishwesh.bharati@gmail.com

    ReplyDelete
  9. Hi Binod,please could you send me the code for image comparisons using imagemagick and java. I need it urgently for a project. I have done some work with JAI, but i have problems using it for texture analysis. I would like to try your method. Thanks a mill

    email - dammyversion1@yahoo.com

    ReplyDelete
  10. Hi Binod..
    nice article and blog. Well can you send me the code for image comparisons using imagemagic and java? I am trying out various ways to do this. This is one way i wish to try.
    Thanks in advance.

    email id - gogo93@gmail.com

    ReplyDelete
  11. Hi Binod,

    Nice blog, After reading this blog am able to compare two images in command line. Actually i want to use this command in java.

    If possible can u send me the code at srajtest@gmail.com

    Thanks

    ReplyDelete
  12. Hi Binod, could you please send me the java code for image comparisons using imagemagick.
    I learnt how to compare images in commandline from your blog. but i wanted to implement it in java for my project.

    my id: srajtest@gmail.com

    ReplyDelete
  13. Hi Binod,
    I learnt how to compare images in commandline from your blog. but i got to implement it in java for my project.Could you please send me the java code for image comparisons using imagemagick.
    Thanks in advance...

    ma id: sanju_p89@yahoo.co.in

    ReplyDelete
  14. hi.. i want java code to compare two images for my project..will you help

    ReplyDelete
  15. sir,
    we are doing project on iris recognition in mobile phones by usins sony ericcson emulator.
    for that we need a java program about comparing images if both the images are same then the phone should unlock.
    plz help us
    thank u

    ReplyDelete
  16. Hi Binod,
    i need code to compare two images can u plz help me with the code.. will u plz send it to swati_kulakarni@rediffmail.com plzzz...

    ReplyDelete
  17. Hi binod, i need the java code so i can use it in a project.
    send to me at sayed.abdelgleel@lognlabs.com

    thanks,
    Sayed

    ReplyDelete
  18. i need the java code to compare two images..can u pls help..pls mail it to me at aarthild@gmail.com


    thanks

    ReplyDelete
  19. hi binod,
    we need the image comparisson jave code for our project pls send the code to rgopikrishnan91@gmail.com
    thanks in advance

    ReplyDelete
  20. hey i used it. but i need it to implement in java.. can u please provide ur favour to me. my mail.id is prakukns@gmail.com

    ReplyDelete
  21. Binod, if you call native windows commands from a Java program, it sort of defeats the point of using Java, doesn't it ? Java programs should be compatible with any operating system, not just windows.

    ReplyDelete
  22. we need the image comparisson jave code for our project pls send the code to s.shyamprasath@gmail.com

    ReplyDelete
  23. we need the image comparison jave code for our project pls send the code to prankypuneet@gmail.com

    as early as possible.

    Thanks
    :-)

    ReplyDelete
  24. need the image comparisson jave code for our project pls send the code to 334143@gmail.com

    Thnx in advance

    ReplyDelete
  25. halo i need the image comparision code in java i ve got code but its working if its true but not for different images and one more thing is the path i need to describe from where that image has to come i want automatically to uploat that image
    reply to Sonalikarwa27@gmail.com........... please sir make sure to help me with the need

    ReplyDelete
  26. i need the image comparision jave code for our project pls send the code to sonal2706@gmail.com


    thanks in advance..:-)

    ReplyDelete
  27. hi binod i need the code for comparision of two images using java and image magick can u please mail me that to m.santhosh2003@gmail.com

    ReplyDelete
  28. Is it possible to find percentage of similarities between two images using this software??please reply me.Thanks in advance.

    ReplyDelete
  29. Hi all,

    Even i need the code to do image compare in Java.Please the code.Thanks.Sumitsingh09@gmail.com

    Regards,
    Sumit

    ReplyDelete

Please put your feedback or your any question related to this blog. Thanks.