开发者

Java: Unit testing image manipulations

开发者 https://www.devze.com 2023-01-15 09:31 出处:网络
I have a method that deals with an image. The method takes one image, performs some manipulations over it and returns another image:

I have a method that deals with an image. The method takes one image, performs some manipulations over it and returns another image:

public BufferedImage manipulateImage (Image image) {
    ...
}

I'm not sure if there are any best practices of writing unit tests for such activities. What characteristics of the image should be checked at a first place? How to check if the image was not spoiled? For insta开发者_JAVA百科nce, once I faced a problem when GIF images became color-inverted after reading them with ImageIO and saving back.


Get your original image (x), run the transform and save the manipulated image (y), physically check yourself that y is what you want to test. Your test is then that F(x) = y, if you have both x and y in your src/test/resources directory you can compare y to the output of your test.

You may also be interested in http://pdiff.sourceforge.net/ (C++ not Java) should you not need to test for 100% equality.

Edit: also see this question - Image comparison - fast algorithm

0

精彩评论

暂无评论...
验证码 换一张
取 消