Class ImageComparator
- java.lang.Object
-
- com.github.loyada.jdollarx.visual.ImageComparator
-
public class ImageComparator extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<BufferedImage>
getErrorImage(BufferedImage img1, BufferedImage img2)
Capture an error image for an assertion of equality of two images.static Optional<BufferedImage>
getFuzzyErrorImage(BufferedImage img1, BufferedImage img2)
Capture an error image which is the result of a failed assertion of similarity of two images.static void
verifyImagesAreEqual(BufferedImage img1, BufferedImage img2)
static void
verifyImagesAreEqualFilteringInterestingAreas(BufferedImage filterImg, BufferedImage img1, BufferedImage img2)
Verify equality to a reference image, ignoring areas that we are uninterested in.static void
verifyImagesAreEqualWithShift(BufferedImage img1, BufferedImage img2, int maxShift)
Verify images are equal, allowing for some shift(offset) between themstatic void
verifyImagesAreSimilar(BufferedImage img1, BufferedImage img2, int maxBadPixelsRatio)
static void
verifyImagesAreSimilarFilteringInterestingAreas(BufferedImage filterImage, BufferedImage refImage, BufferedImage img, int maxBadPixelsRatio)
Similar to verifyImagesAreSimilarWithShift() but also provides a "filter image" that highlights the areas we focus on.static void
verifyImagesAreSimilarWithShift(BufferedImage img1, BufferedImage img2, int maxBadPixelsRatio, int maxShift)
Verify images are "similar", allowing for some shift (offset) between the images.
-
-
-
Method Detail
-
verifyImagesAreSimilar
public static void verifyImagesAreSimilar(BufferedImage img1, BufferedImage img2, int maxBadPixelsRatio)
-
verifyImagesAreSimilarWithShift
public static void verifyImagesAreSimilarWithShift(BufferedImage img1, BufferedImage img2, int maxBadPixelsRatio, int maxShift)
Verify images are "similar", allowing for some shift (offset) between the images. "Similar" means that the ratio of total pixels to the pixels that are "significantly different" is less than the given threshold.- Parameters:
img1
- first imageimg2
- second imagemaxBadPixelsRatio
- max allowed ratio between total pixels and pixels that are found to be "significantly different"maxShift
- max allowed shift between the images, in pixels
-
verifyImagesAreSimilarFilteringInterestingAreas
public static void verifyImagesAreSimilarFilteringInterestingAreas(BufferedImage filterImage, BufferedImage refImage, BufferedImage img, int maxBadPixelsRatio)
Similar to verifyImagesAreSimilarWithShift() but also provides a "filter image" that highlights the areas we focus on. The filter image has white pixels in interesting areas and black pixels in areas that are not interesting. This allows to filter out areas with no information. T "Similar" means that the ratio of total pixels of interest based on the filter image, and the pixels that are "significantly different" is less than the given threshold. Unlike verifyImagesAreSimilarWithShift(), here max shift is set to 2 pixels.- Parameters:
filterImage
- - "filter image" that highlights the areas of interestrefImage
- - the reference imageimg
- - the image we are assertingmaxBadPixelsRatio
- - max allowed ration between total pixels "of interest" and pixels that are significantly different.
-
verifyImagesAreEqualWithShift
public static void verifyImagesAreEqualWithShift(BufferedImage img1, BufferedImage img2, int maxShift)
Verify images are equal, allowing for some shift(offset) between them- Parameters:
img1
-img2
-maxShift
- - max allowed shift in pixels
-
getErrorImage
public static Optional<BufferedImage> getErrorImage(BufferedImage img1, BufferedImage img2)
Capture an error image for an assertion of equality of two images. If the images are equal it returns on empty Optional. The error image displayed a faded out version of the original image, overlaid with the bright red pixels in the location of errors.- Parameters:
img1
- first imageimg2
- second image- Returns:
- and optional of the error image.
-
getFuzzyErrorImage
public static Optional<BufferedImage> getFuzzyErrorImage(BufferedImage img1, BufferedImage img2)
Capture an error image which is the result of a failed assertion of similarity of two images. If the images are similar it returns on empty Optional. Capture an error image which is the result of a failed assertion of similarity of two images. If the images are similar it returns on empty Optional.- Parameters:
img1
- - first imageimg2
- - second image- Returns:
- - an optional of the error image.
-
verifyImagesAreEqual
public static void verifyImagesAreEqual(BufferedImage img1, BufferedImage img2)
-
verifyImagesAreEqualFilteringInterestingAreas
public static void verifyImagesAreEqualFilteringInterestingAreas(BufferedImage filterImg, BufferedImage img1, BufferedImage img2)
Verify equality to a reference image, ignoring areas that we are uninterested in. This is done by providing an additional "filter image" that displays white pixels in the interesting areas and black pixels in the rest.- Parameters:
filterImg
- - "filter image" that tells the comparator the areas to focus onimg1
- - captured imageimg2
- - reference image
-
-