Static function to check if the RGB error of BufferdImage is within the specified ratio in Java


Operation check environment


	 *Pixel-by-pixel Red,Green,Assert the element value of the Blue color.
	 *Difference in element values(±)Increases or decreases 5%Is allowed.
	static void assertImages(BufferedImage actual, BufferedImage expected) {
		assertThat("The image size being compared is different (vertical)", actual.getHeight(), is(expected.getHeight()));
		assertThat("The image size being compared is different (horizontal)", actual.getWidth(), is(expected.getWidth()));

		//Percentage tolerate error
		//Numerical value tolerate error(±)

		int width = actual.getWidth();
		int height = actual.getHeight();
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				Color actualColor = new Color(actual.getRGB(x, y));
				Color expectedColor = new Color(expected.getRGB(x, y));

				assertThat("Color element values are acceptable(±" + ACCEPTABLE_PERCENTAGE + "%)Beyond: Red",
						(double) actualColor.getRed(),
						is(closeTo((double) expectedColor.getRed(), ACCEPTABLE_DIFFERENCE)));

				assertThat("Color element values are acceptable(±" + ACCEPTABLE_PERCENTAGE + "%)Beyond: Green",
						(double) actualColor.getGreen(),
						is(closeTo((double) expectedColor.getGreen(), ACCEPTABLE_DIFFERENCE)));

				assertThat("Color element values are acceptable(±" + ACCEPTABLE_PERCENTAGE + "%)Beyond: Blue",
						(double) actualColor.getBlue(),
						is(closeTo((double) expectedColor.getBlue(), ACCEPTABLE_DIFFERENCE)));

Recommended Posts

Static function to check if the RGB error of BufferdImage is within the specified ratio in Java
[Java] Is it unnecessary to check "identity" in the implementation of the equals () method?
The milliseconds to set in /lib/ of Java jre is UTC
[Java] Check if the character string is composed only of blanks (= Blank)
Even if I want to convert the contents of a data object to JSON in Java, there is a circular reference ...
A quick explanation of the five types of static in Java
Command to check the number and status of Java threads
How to derive the last day of the month in Java
[Note] What to do if bundle install in Chapter 3 of the rails tutorial is not possible
What to do if Cloud9 is full in the Rails tutorial
What is @Override or @SuppressWarnings ("SleepWhileInLoop") in front of the function? ?? ??
Determine if the strings to be compared are the same in Java
How to solve the unknown error when using slf4j in Java
How to check for the contents of a java fixed-length string
How to get the length of an audio file in java
How to increment the value of Map in one line in Java
If you do not call shutdownNow when the transfer is completed in the Java SDK of AWS S3, threads will continue to remain
Implementation of like function in Java
What to do if the prefix c is not bound in JSP
The story of forgetting to close a file in Java and failing
[Java Servlet] The road of Senri is also one step to the first
Use static initialization block to initialize List / Set of static fields in Java
Memo: [Java] If a file is in the monitored directory, process it.
This and that of the implementation of date judgment within the period in Java
Error when the member of Entity class used in SpringWebFlux is final
How to find the total number of pages when paging in Java
How to get the absolute path of a directory running in Java
From Java9, the constructor of the class corresponding to primitive types is deprecated.
Android development, how to check null in the value of JSON object
What is CHECKSTYLE: OFF found in the Java source? Checkstyle to know from
Get the result of POST in Java
Check the contents of the Java certificate store
Java reference to understand in the figure
[Java] How to use the hasNext function
How to get the date in java
Output of the book "Introduction to Java"
[Processing × Java] How to use the function
The story of writing Java in Emacs
[Java] Check the number of occurrences of characters
Possibility when deploying to EC2 but nothing is displayed in the error log
If you want to satisfy the test coverage of private methods in JUnit
If the parameter is an array, how to include it in Stopara's params.permit
How to check if an instance variable is defined in a Ruby class
How to resolve the "OpenSSH keys only supported if ED25519 is available" error
How to check the latest version of io.spring.platform to describe in pom.xml of Spring (STS)
[Ruby] Meaning of &. How to avoid the error when the receiver (object) is nil
Make the JSON of the snake case correspond to the field of the camel case in Java (JVM)
[Java] Where is the implementation class of annotation that exists in Bean Validation?
Let's refer to C ++ in the module of AndroidStudio other project (Java / kotlin)
Code that deletes all files of the specified prefix in AWS S3 (Java)
Is it mainstream not to write the closing tag of <P> tag in Javadoc?
Conditional branching of the result of SQL statement to search only one in Java
[Rails] If CSS is not applied in collection_select, check if class can be specified.
What is ... (3 dots) found in the Java source? Variadic arguments to know from
Sample code to get the values of major SQL types in Java + MySQL 8.0
[Java] When putting a character string in the case of a switch statement, it is necessary to make it a constant expression
[Java] What to do if the contents saved in the DB and the name of the enum are different in the enum that reflects the DB definition