Testing and debugging module

Tools for testing and debugging.

Namespaces

namespace dip::testing
Tools for testing and debugging.

Classes

class dip::testing::Timer
A timer object to help time algorithm execution.

Enums

enum class dip::Option::CompareImagesMode: uint8{ EXACT, APPROX, APPROX_REL, FULL }
How to compare images in dip::testing::CompareImages.

Functions

template<typename TPI, int DIGITS = 4>
void dip::testing::PrintPixelValues(dip::Image const& img)
Outputs pixel values of a small image to stdout.
auto dip::testing::CompareImages(dip::Image const& img1, dip::Image const& img2, dip::Option::CompareImagesMode mode = Option::CompareImagesMode::EXACT, dip::dfloat epsilon = 1e-6) -> bool
Compares two images. Returns test result and prints to stdout the reason of failure if the test fails.

Operators

auto dip::testing::operator<<(std::ostream& os, dip::testing::Timer const& timer) -> std::ostream&
Reports elapsed time to a stream.

Enum documentation

enum class dip::Option::CompareImagesMode: uint8

How to compare images in dip::testing::CompareImages.

Enumerators
EXACT = 0 Compare only the sample values (and image sizes).
APPROX = 1 Compare the sample values (and image sizes), to match within epsilon in absolute terms.
APPROX_REL = 2 Compare the sample values (and image sizes), to match within epsilon in relative terms.
FULL = 3 Compare for identical sample values as well as tensor shape, color space, and pixel size.

Function documentation

template<typename TPI, int DIGITS = 4>
void dip::testing::PrintPixelValues(dip::Image const& img)

Outputs pixel values of a small image to stdout.

If the image is a tensor image, shows only the first tensor component.

The first template parameter must match the image’s data type.

An optional second template parameter determines the precision for displaying floating-point values.

bool dip::testing::CompareImages(dip::Image const& img1, dip::Image const& img2, dip::Option::CompareImagesMode mode = Option::CompareImagesMode::EXACT, dip::dfloat epsilon = 1e-6)

Compares two images. Returns test result and prints to stdout the reason of failure if the test fails.

Returns true only if they have the same sizes, number of tensor elements, and sample values. If the result is false, it prints a message to stdout that starts with [dip::testing::CompareImages] and gives the reason that the test failed.

If mode is dip::Option::CompareImagesMode::APPROX, the sample values must all be within epsilon, which defaults to 1e-6 (see dip::MaximumAbsoluteError). For this mode of operation there is an overloaded function that takes epsilon as the 3rd argument (i.e. you can skip the mode parameter):

dip::CompareImages( img1, img2 );       // samples must be identical
dip::CompareImages( img1, img2, 1e-3 ); // samples must be within 1e-3 of each other

If mode is dip::Option::CompareImagesMode::APPROX_REL, the relative difference between sample values must be less than epsilon (see dip::MaximumRelativeError).

If mode is dip::Option::CompareImagesMode::FULL, the sample values must match exactly, and non-data properties (tensor shape, color space and pixel size) must also match exactly.

This function does not compare strides.