ImageDev

CompareImage

Performs a comparison test between two images and outputs the number of pixels that successfully passed the test.

Access to parameter description

For an introduction: This algorithm computes the number of pixels which fulfill a point-wise comparison criterion between two images $I_1$ and $I_2$.
The proposed comparison criteria are less-than, less-or-equal, equal-to, greater-or-equal, greater-than, and not-equal-to.

Note : CompareImage can be useful to check whether two images are exactly identical. Both images must have same size and type.

See also

Function Syntax

This function returns the outputMeasurement output parameter.
// Function prototype.
CompareMsr::Ptr
compareImage( std::shared_ptr< iolink::ImageView > inputImage1,
              std::shared_ptr< iolink::ImageView > inputImage2,
              CompareImage::ComparisonCriterion comparisonCriterion,
              CompareMsr::Ptr outputMeasurement = NULL );
This function returns the outputMeasurement output parameter.
// Function prototype.
compare_image( input_image1,
               input_image2,
               comparison_criterion = CompareImage.ComparisonCriterion.NOT_EQUAL_TO,
               output_measurement = None )
This function returns the outputMeasurement output parameter.
// Function prototype.
public static CompareMsr
CompareImage( IOLink.ImageView inputImage1,
              IOLink.ImageView inputImage2,
              CompareImage.ComparisonCriterion comparisonCriterion = ImageDev.CompareImage.ComparisonCriterion.NOT_EQUAL_TO,
              CompareMsr outputMeasurement = null );

Class Syntax

Parameters

Class Name CompareImage

Parameter Name Description Type Supported Values Default Value
input
inputImage1
The first input image. Image Binary, Label, Grayscale or Multispectral nullptr
input
inputImage2
The second input image. Its dimensions and type must be the same as the first input. Image Binary, Label, Grayscale or Multispectral nullptr
input
comparisonCriterion
The comparison test to perform between images.
LESS_THAN The number of pixels of the first image having an intensity strictly less than in the second image.
LESS_OR_EQUAL The number of pixels of the first image having an intensity less than or equal to that of the second image.
EQUAL_TO The number of pixels of the first image having an intensity equal to that of the second image.
GREATER_OR_EQUAL The number of pixels of the first image having an intensity greater than or equal to that of the second image.
GREATER_THAN The number of pixels of the first image having an intensity strictly greater than in the second image.
NOT_EQUAL_TO The number of pixels of the first image having an intensity different than in the second image.
Enumeration NOT_EQUAL_TO
output
outputMeasurement
The output measurement result. CompareMsr nullptr

Object Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

CompareImage compareImageAlgo;
compareImageAlgo.setInputImage1( polystyrene );
compareImageAlgo.setInputImage2( polystyrene );
compareImageAlgo.setComparisonCriterion( CompareImage::ComparisonCriterion::NOT_EQUAL_TO );
compareImageAlgo.execute();

std::cout << "pixelCount: " << compareImageAlgo.outputMeasurement()->pixelCount( 0 , 0 ) ;
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

compare_image_algo = imagedev.CompareImage()
compare_image_algo.input_image1 = polystyrene
compare_image_algo.input_image2 = polystyrene
compare_image_algo.comparison_criterion = imagedev.CompareImage.NOT_EQUAL_TO
compare_image_algo.execute()

print( "pixelCount: ", str( compare_image_algo.output_measurement.pixel_count( 0 , 0 ) ) )
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

CompareImage compareImageAlgo = new CompareImage
{
    inputImage1 = polystyrene,
    inputImage2 = polystyrene,
    comparisonCriterion = CompareImage.ComparisonCriterion.NOT_EQUAL_TO
};
compareImageAlgo.Execute();

Console.WriteLine( "pixelCount: " + compareImageAlgo.outputMeasurement.pixelCount( 0 , 0 ) );

Function Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = compareImage( polystyrene, polystyrene, CompareImage::ComparisonCriterion::NOT_EQUAL_TO );

std::cout << "pixelCount: " << result->pixelCount( 0 , 0 ) ;
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

result = imagedev.compare_image( polystyrene, polystyrene, imagedev.CompareImage.NOT_EQUAL_TO )

print( "pixelCount: ", str( result.pixel_count( 0 , 0 ) )  )
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

CompareMsr result = Processing.CompareImage( polystyrene, polystyrene, CompareImage.ComparisonCriterion.NOT_EQUAL_TO );

Console.WriteLine(  "pixelCount: " + result.pixelCount( 0 , 0 )  );