vc2-picture-compare

A command-line utility which compares pairs of raw pictures (see Video file format), or pairs of directories containing a series of raw pictures.

Usage

Given a pair of images in raw format (see Video file format), these images can be compared as follows:

$ vc2-picture-compare image_a.raw image_b.raw
Pictures are different:
  Y: Different: PSNR = 55.6 dB, 1426363 pixels (68.8%) differ
  C1: Different: PSNR = 57.7 dB, 662607 pixels (63.9%) differ
  C2: Different: PSNR = 56.8 dB, 703531 pixels (67.9%) differ

Alternatively a pair of directories containing images whose filenames end with a number (and the extensions .raw and .json). For example:

$ vc2-picture-compare ./directory_a/ ./directory_b/
Comparing ./directory_a/picture_0.raw and ./directory_b/picture_0.raw:
  Pictures are identical
Comparing ./directory_a/picture_1.raw and ./directory_b/picture_1.raw:
  Pictures are different:
    Y: Different: PSNR = 55.6 dB, 1426363 pixels (68.8%) differ
    C1: Different: PSNR = 57.7 dB, 662607 pixels (63.9%) differ
    C2: Different: PSNR = 56.8 dB, 703531 pixels (67.9%) differ
Comparing ./directory_a/picture_2.raw and ./directory_b/picture_2.raw:
  Pictures are identical
Summary: 2 identical, 1 different

Differences in the encoded values are reported separately for each picture component.

Peak Signal to Noise Ratio (PSNR) figures give the PSNR of the raw integer signal values (and not, for example, linear light levels).

Note

PSNR is computed as:

\[\begin{split}\text{MeanSquareError} &= \sum_{i, j} (E_{i, j} - A_{i, j})^2 \\ \text{MaxE} &= \max_{i, j} (E_{i, j}) \\ \text{PSNR} &= 20 \log_{10}(\text{MaxE}) - 10 \log_{10}(\text{MeanSquareError})\end{split}\]

Where \(E_{i,j}\) is pixel \((i, j)\) of the raw integer signal value of the test image and \(A_{i, j}\) is pixel \((i, j)\) of the raw integer values of the decoded image.

The number of pixels which are not bit-for-bit identical is also reported.

The tool also compares the metadata of the raw images and will flag up differences here too, for example:

$ vc2-picture-compare picture_hd.raw picture_cif.raw
Picture numbers are different:
Video parameters are different:
  - frame_width: 1920
  + frame_width: 352
  - frame_height: 1080
  + frame_height: 288
  - color_diff_format_index: color_4_2_2 (1)
  + color_diff_format_index: color_4_2_0 (2)
    source_sampling: progressive (0)
    top_field_first: True
  - frame_rate_numer: 50
  + frame_rate_numer: 25
  - frame_rate_denom: 1
  + frame_rate_denom: 2
  - pixel_aspect_ratio_numer: 1
  + pixel_aspect_ratio_numer: 12
  - pixel_aspect_ratio_denom: 1
  + pixel_aspect_ratio_denom: 11
  - clean_width: 1920
  + clean_width: 352
  - clean_height: 1080
  + clean_height: 288
    left_offset: 0
    top_offset: 0
  - luma_offset: 64
  + luma_offset: 0
  - luma_excursion: 876
  + luma_excursion: 255
  - color_diff_offset: 512
  + color_diff_offset: 128
  - color_diff_excursion: 896
  + color_diff_excursion: 255
  - color_primaries_index: hdtv (0)
  + color_primaries_index: sdtv_625 (2)
  - color_matrix_index: hdtv (0)
  + color_matrix_index: sdtv (1)
    transfer_function_index: tv_gamma (0)

When picture metadata differs, the pixel values will not be compared since the difference in metadata typically means a difference in format making the pictures incomparable.

Generating difference masks

The vc2-picture-compare tool can optionally output a simple difference mask image using --difference-mask/-D. The generated image contains white pixels wherever the inputs differed and black pixels wherever they were identical. The generated difference mask is output as a raw file of the same format as the two input files. This mode is only supported when two individual files are provided, not two directories.

For example:

$ vc2-picture-compare \
      image_a.raw \
      image_b.raw \
      --difference-mask difference_mask.raw
Pictures are different:
  Y: Different: PSNR = 55.6 dB, 1426363 pixels (68.8%) differ
  C1: Different: PSNR = 57.7 dB, 662607 pixels (63.9%) differ
  C2: Different: PSNR = 56.8 dB, 703531 pixels (67.9%) differ

Arguments

The complete set of arguments can be listed using --help

usage: vc2-picture-compare [-h] [--version] [--difference-mask FILENAME]
                           filename_a filename_b

Compare a pair of pictures in the raw format used by the VC-2 conformance
software.

positional arguments:
  filename_a            The filename of a .raw or .json raw picture, or a
                        directory containing a series of .raw and .json files
                        whose names end in a number.
  filename_b            The filename of a .raw or .json raw picture, or a
                        directory containing a series of .raw and .json files
                        whose names end in a number.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit

difference image options:
  --difference-mask FILENAME, -D FILENAME
                        Output a difference mask image to the specified file.
                        This mask will contain white pixels wherever the input
                        images differ and black pixels where they match. Only
                        available when comparing files (not directories).