module

CrImage::Util::VisualDiff

Visual difference detection and highlighting.

Generates diff images showing pixel differences between two images, useful for visual regression testing.

Class methods

diff(img1 : Image, img2 : Image, threshold : Int32 = 10, highlight_color : Color::Color = Color::RGBA.new(255_u8, 0_u8, 0_u8, 255_u8), show_unchanged : Bool = true) : RGBA

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

Source
diff_count(img1 : Image, img2 : Image, threshold : Int32 = 10) : Int32

Counts the number of different pixels between two images.

Parameters:

  • img1 : First image
  • img2 : Second image
  • threshold : Color difference threshold (0-255, default: 10)

Returns: Number of pixels that differ

Raises: ArgumentError if images have different dimensions

Source
diff_percent(img1 : Image, img2 : Image, threshold : Int32 = 10) : Float64

Calculates the percentage of different pixels.

Parameters:

  • img1 : First image
  • img2 : Second image
  • threshold : Color difference threshold (0-255, default: 10)

Returns: Percentage of different pixels (0.0 to 100.0)

Source
identical?(img1 : Image, img2 : Image, threshold : Int32 = 10, tolerance : Int32 = 0) : Bool

Checks if two images are visually identical within threshold.

Parameters:

  • img1 : First image
  • img2 : Second image
  • threshold : Color difference threshold (default: 10)
  • tolerance : Maximum allowed different pixels (default: 0)

Returns: true if images are identical within tolerance

Source