Class PerceptualImageDifferencing
- java.lang.Object
-
- com.crawljax.stateabstractions.visual.PerceptualImageDifferencing
-
public class PerceptualImageDifferencing extends Object
Adapted from Perceptual Image Difference Utility.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPerceptualImageDifferencing.BuilderBuilds parameter list for the PerceptualDiff constructor.protected classPerceptualImageDifferencing.ComparisonForkJoin idioms adapted fromsumOfSquaressample.private classPerceptualImageDifferencing.PyramidTaskConverts color values and constructs Laplacian pyramids.
-
Field Summary
Fields Modifier and Type Field Description private intadaptationLevelprivate static intALPHA_MASKstatic intCOLOR_FAILstatic intCOLOR_PASSprivate doublecolorFactorprivate static doubleEPSILONprivate booleanfailFastprivate static booleanFAST_POWprivate doublefieldOfViewprivate doublegammaprivate static doubleKAPPAprivate static float[]KERNELFilter kernel for Laplacian convolution.private doubleluminanceprivate booleanluminanceOnlyprivate double[]lutprivate static intMAX_PYR_LEVELSprivate doublenumOneDegreePixelsprivate intthresholdPixelsprivate static doubleXWprivate static doubleYWprivate static doubleZW
-
Constructor Summary
Constructors Constructor Description PerceptualImageDifferencing(double fieldOfView, int thresholdPixels, boolean failFast, double gamma, double luminance, boolean luminanceOnly, double colorFactor)Creates PerceptualDiff instance with specified parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcompare(ForkJoinPool pool, BufferedImage imgA, BufferedImage imgB, BufferedImage imgDiff)Compares images using Yee's method.protected static voidconstruct(float[][] levels, int width, int height)Constructs the Laplacian pyramid by successively copying earlier levels and blurring them.protected voidconvert(int[] rgb, float[] a, float[] b, float[] lum)Converts RGB to AB and luminance.private static voidconvolveAndTranspose(float[] src, float[] dst, int width, int height)Convolves imagesrcwith 1D filter kernel and stores it transposed indst.private static doublecsf(double cpd, double lum)Computes the contrast sensitivity function (Barten SPIE 1989) given the cycles per degree (cpd) and luminance (lum).voiddump()Prints some parameters to the log.private static doublefastpow(double a, double b)Returns the first argument raised to the power of the second argument.private static doublemask(double contrast)Visual Masking Function from Daly 1993private static doublepow(double a, double b)private static doubletvi(double adaptationLuminance)Given the adaptation luminance, computes the threshold of visibility in cd per m^2.
-
-
-
Field Detail
-
COLOR_PASS
public static final int COLOR_PASS
- See Also:
- Constant Field Values
-
COLOR_FAIL
public static final int COLOR_FAIL
- See Also:
- Constant Field Values
-
MAX_PYR_LEVELS
private static final int MAX_PYR_LEVELS
- See Also:
- Constant Field Values
-
ALPHA_MASK
private static final int ALPHA_MASK
- See Also:
- Constant Field Values
-
XW
private static final double XW
- See Also:
- Constant Field Values
-
YW
private static final double YW
- See Also:
- Constant Field Values
-
ZW
private static final double ZW
- See Also:
- Constant Field Values
-
EPSILON
private static final double EPSILON
- See Also:
- Constant Field Values
-
KAPPA
private static final double KAPPA
- See Also:
- Constant Field Values
-
KERNEL
private static final float[] KERNEL
Filter kernel for Laplacian convolution.
-
FAST_POW
private static final boolean FAST_POW
- See Also:
- Constant Field Values
-
colorFactor
private final double colorFactor
-
fieldOfView
private final double fieldOfView
-
gamma
private final double gamma
-
luminance
private final double luminance
-
luminanceOnly
private final boolean luminanceOnly
-
thresholdPixels
private final int thresholdPixels
-
failFast
private final boolean failFast
-
numOneDegreePixels
private final double numOneDegreePixels
-
adaptationLevel
private final int adaptationLevel
-
lut
private final double[] lut
-
-
Constructor Detail
-
PerceptualImageDifferencing
public PerceptualImageDifferencing(double fieldOfView, int thresholdPixels, boolean failFast, double gamma, double luminance, boolean luminanceOnly, double colorFactor)Creates PerceptualDiff instance with specified parameters.- Parameters:
fieldOfView- field of view in degreesthresholdPixels- failure thresholdfailFast- whether to fail immediately when threshold is reachedgamma- value to convert rgb into linear spaceluminance- white luminanceluminanceOnly- whether to ignore chroma in comparisoncolorFactor- how much of color to use
-
-
Method Detail
-
construct
protected static void construct(float[][] levels, int width, int height)Constructs the Laplacian pyramid by successively copying earlier levels and blurring them.
-
convolveAndTranspose
private static void convolveAndTranspose(float[] src, float[] dst, int width, int height)Convolves imagesrcwith 1D filter kernel and stores it transposed indst.Adapted from Jerry Huxtable's Gaussian Filter
-
tvi
private static double tvi(double adaptationLuminance)
Given the adaptation luminance, computes the threshold of visibility in cd per m^2.TVI means Threshold vs Intensity function.
This version comes from Ward Larson Siggraph 1997
-
csf
private static double csf(double cpd, double lum)Computes the contrast sensitivity function (Barten SPIE 1989) given the cycles per degree (cpd) and luminance (lum).
-
mask
private static double mask(double contrast)
Visual Masking Function from Daly 1993
-
pow
private static double pow(double a, double b)
-
fastpow
private static double fastpow(double a, double b)Returns the first argument raised to the power of the second argument.This approximate implementation from martin.ankerl.com is several times faster than
Math.pow.For an implementation with adjustable accuracy, see article by Harrison Ainsworth: Fast pow() With Adjustable Accuracy.
- Parameters:
a- the baseb- the exponent- Returns:
- the value ab
-
dump
public void dump()
Prints some parameters to the log.
-
compare
public void compare(ForkJoinPool pool, BufferedImage imgA, BufferedImage imgB, BufferedImage imgDiff)
Compares images using Yee's method.References: A Perceptual Metric for Production Testing, Hector Yee, Journal of Graphics Tools 2004.
- Parameters:
pool- fork-join pool for task executionimgA- first of two images to compareimgB- second of two images to compareimgDiff- accumulates differences (optional)
-
convert
protected void convert(int[] rgb, float[] a, float[] b, float[] lum)Converts RGB to AB and luminance.- Parameters:
rgb- pixel valuesa- Ab- Blum- Y * luminance
-
-