Best way to compare 2 images in Java jUnit?

3.7k views Asked by At

I'm writing a junit test case to validate a cropping and resizing class. The class is fairly simple, it just delegates the calls to ImageMagick via Im4Java. But to do things properly, I am trying to write up a jUnit test case.

I manually created expected result images using Photoshop and am trying to compare them to the images produced by my crop/resize class. The problem is that the headers that ImageMagick write and those by Photoshop differ. So a simple byte-by-byte comparison will not work.

ImageMagick offers a compare function, which when run from command line shows no pixel differences between the expected result and that produced by my class. But Im4Java does not provide any wrapper methods to this compare function.

Short of having to call Runtime.exec() myself, is there a way I can compare these two images in my test case?

1

There are 1 answers

0
yshavit On BEST ANSWER

It looks like Im4Java has a CompareCmd class that will do the trick.