CrImage::Util::VisualDiff
Visual difference detection and highlighting.
Generates diff images showing pixel differences between two images, useful for visual regression testing.
Class methods
Generates a diff image highlighting differences between two images.
Pixels that differ beyond the threshold are highlighted in the specified color. Unchanged pixels are shown in grayscale (dimmed).
Parameters:
img1: First image (reference)img2: Second image (comparison)threshold: Color difference threshold (0-255, default: 10)highlight_color: Color for different pixels (default: red)show_unchanged: Whether to show unchanged pixels in grayscale (default: true)
Returns: Diff image with highlighted differences
Raises: ArgumentError if images have different dimensions
Counts the number of different pixels between two images.
Parameters:
img1: First imageimg2: Second imagethreshold: Color difference threshold (0-255, default: 10)
Returns: Number of pixels that differ
Raises: ArgumentError if images have different dimensions
Calculates the percentage of different pixels.
Parameters:
img1: First imageimg2: Second imagethreshold: Color difference threshold (0-255, default: 10)
Returns: Percentage of different pixels (0.0 to 100.0)
Checks if two images are visually identical within threshold.
Parameters:
img1: First imageimg2: Second imagethreshold: Color difference threshold (default: 10)tolerance: Maximum allowed different pixels (default: 0)
Returns: true if images are identical within tolerance