-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add internally packaged Images class so that distance code in one place
- Loading branch information
1 parent
10146e0
commit fc5aff9
Showing
3 changed files
with
54 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
jlatexmath/src/main/java/org/scilab/forge/jlatexmath/internal/util/Images.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.scilab.forge.jlatexmath.internal.util; | ||
|
||
import java.awt.Color; | ||
import java.awt.image.BufferedImage; | ||
|
||
public final class Images { | ||
|
||
private Images() { | ||
//prevent instantiation | ||
} | ||
|
||
public static double DISTANCE_THRESHOLD=40; | ||
|
||
public static double distance(BufferedImage imgA, BufferedImage imgB) { | ||
// The images must be the same size. | ||
if (imgA.getWidth() == imgB.getWidth() && imgA.getHeight() == imgB.getHeight()) { | ||
int width = imgA.getWidth(); | ||
int height = imgA.getHeight(); | ||
|
||
double mse = 0; | ||
// Loop over every pixel. | ||
for (int y = 0; y < height; y++) { | ||
for (int x = 0; x < width; x++) { | ||
Color ca = new Color(imgA.getRGB(x, y)); | ||
Color cb = new Color(imgB.getRGB(x, y)); | ||
double variance = sqr(ca.getRed() - cb.getRed()) // | ||
+ sqr(ca.getBlue() - cb.getBlue()) // | ||
+ sqr(ca.getGreen() - cb.getGreen()) // | ||
+ sqr(ca.getAlpha() - cb.getAlpha()); | ||
mse += variance; | ||
} | ||
} | ||
return Math.sqrt(mse / height / width); | ||
} else { | ||
return -1; | ||
} | ||
} | ||
|
||
private static double sqr(double x) { | ||
return x * x; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters