This algorithm performs a cross-correlation, or correlation with a mutiplication metric, between a gray
level image I and a gray level kernel K, returning the correlation image O.
The different possibilities for selecting a correlation peak are presented below using a 1-D correlation
between an image and kernel. In the image, the kernel appears 6 times with different contrast and luminosity.
Figure 1. 1D image and kernel
The 6 examples show the kernel appearing with different contrast and luminosity.
Figure 2. Examples of possible 1D correlation
The cross-correlation metric is computed in accordance with the CorrelationMode parameter.
DIRECT Correlation Mode
O(n,m)=kx∑i=1ky∑j=1K(i,j)×I(n+i−kx2,m+j−ky2)
In this mode, 3 of the 6 patterns matching the kernel are detected. These are only high luminosity patterns.
The best matching is obtained for the highest contrast and luminosity pattern.
Figure 3. Example of 1D direct cross-correlation
MEAN Correlation Mode
O(n,m)=kx∑i=1ky∑j=1(K(i,j)−μ(K))×(I(n+i−kx2,m+j−ky2)−μ(I)(n,m))
In this mode, 2 of the 6 patterns matching the kernel are detected. These are only high
contrast patterns. The confidence rate is the same for the two 2 patterns.
Figure 4. Example of 1D mean cross-correlation
Note: This algorithm returns the main correlation peak in the outputMeasurement object. More
correlation peaks can be extracted from the outputImage correlation image with the
LocalMaxima2d algorithm
// Output structure of the cudaCrossCorrelation2d function.structCudaCrossCorrelation2dOutput{/// The output correlation image. Its dimensions are forced to the same values as the input. Its data type is forced to floating point.
std::shared_ptr< iolink::ImageView> outputImage;/// The correlation matching results.CrossCorrelation2dMsr::Ptr outputMeasurement;};// Function prototype CudaCrossCorrelation2dOutput
cudaCrossCorrelation2d( std::shared_ptr< iolink::ImageView> inputImage,
std::shared_ptr< iolink::ImageView> inputKernelImage,CudaCrossCorrelation2d::CorrelationMode correlationMode,CudaCrossCorrelation2d::TilingMode tilingMode,
iolink::Vector2u32 tileSize,CudaContext::Ptr cudaContext,
std::shared_ptr< iolink::ImageView> outputImage =nullptr,CrossCorrelation2dMsr::Ptr outputMeasurement =nullptr);
/// Output structure of the CudaCrossCorrelation2d function.publicstructCudaCrossCorrelation2dOutput{/// /// The output correlation image. Its dimensions are forced to the same values as the input. Its data type is forced to floating point./// publicIOLink.ImageView outputImage;/// The correlation matching results.publicCrossCorrelation2dMsr outputMeasurement;};// Function prototype.publicstaticCudaCrossCorrelation2dOutputCudaCrossCorrelation2d(IOLink.ImageView inputImage,IOLink.ImageView inputKernelImage,CudaCrossCorrelation2d.CorrelationMode correlationMode =ImageDev.CudaCrossCorrelation2d.CorrelationMode.DIRECT,CudaCrossCorrelation2d.TilingMode tilingMode =ImageDev.CudaCrossCorrelation2d.TilingMode.NONE,uint[] tileSize =null,Data.CudaContext cudaContext =null,IOLink.ImageView outputImage =null,CrossCorrelation2dMsr outputMeasurement =null);
Class Syntax
// Command constructor.CudaCrossCorrelation2d();/// Gets the inputImage parameter./// The input grayscale image.
std::shared_ptr< iolink::ImageView> inputImage()const;/// Sets the inputImage parameter./// The input grayscale image.void setInputImage( std::shared_ptr< iolink::ImageView> inputImage );/// Gets the inputKernelImage parameter./// The correlation kernel.
std::shared_ptr< iolink::ImageView> inputKernelImage()const;/// Sets the inputKernelImage parameter./// The correlation kernel.void setInputKernelImage( std::shared_ptr< iolink::ImageView> inputKernelImage );/// Gets the correlationMode parameter./// The normalization mode for correlation.CudaCrossCorrelation2d::CorrelationMode correlationMode()const;/// Sets the correlationMode parameter./// The normalization mode for correlation.void setCorrelationMode(constCudaCrossCorrelation2d::CorrelationMode& correlationMode );/// Gets the tilingMode parameter./// The way to manage the GPU memory.CudaCrossCorrelation2d::TilingMode tilingMode()const;/// Sets the tilingMode parameter./// The way to manage the GPU memory.void setTilingMode(constCudaCrossCorrelation2d::TilingMode& tilingMode );/// Gets the tileSize parameter./// The tile width and height in pixels. They must be greater than or equal to the correlation kernel width and height. This parameter is used only in USER_DEFINED tiling mode.
iolink::Vector2u32 tileSize()const;/// Sets the tileSize parameter./// The tile width and height in pixels. They must be greater than or equal to the correlation kernel width and height. This parameter is used only in USER_DEFINED tiling mode.void setTileSize(const iolink::Vector2u32& tileSize );/// Gets the cudaContext parameter./// CUDA context information.CudaContext::Ptr cudaContext()const;/// Sets the cudaContext parameter./// CUDA context information.void setCudaContext(constCudaContext::Ptr& cudaContext );/// Gets the outputImage parameter./// The output correlation image. Its dimensions are forced to the same values as the input. Its data type is forced to floating point.
std::shared_ptr< iolink::ImageView> outputImage()const;/// Sets the outputImage parameter./// The output correlation image. Its dimensions are forced to the same values as the input. Its data type is forced to floating point.void setOutputImage( std::shared_ptr< iolink::ImageView> outputImage );/// Gets the outputMeasurement parameter./// The correlation matching results.CrossCorrelation2dMsr::Ptr outputMeasurement()const;// Method to launch the command.void execute();
# Property of the inputImage parameter.CudaCrossCorrelation2d.input_image
# Property of the inputKernelImage parameter.CudaCrossCorrelation2d.input_kernel_image
# Property of the correlationMode parameter.CudaCrossCorrelation2d.correlation_mode
# Property of the tilingMode parameter.CudaCrossCorrelation2d.tiling_mode
# Property of the tileSize parameter.CudaCrossCorrelation2d.tile_size
# Property of the cudaContext parameter.CudaCrossCorrelation2d.cuda_context
# Property of the outputImage parameter.CudaCrossCorrelation2d.output_image
# Property of the outputMeasurement parameter.CudaCrossCorrelation2d.output_measurement
// Method to launch the command.
execute()
// Command constructor.CudaCrossCorrelation2d()// Property of the inputImage parameter.CudaCrossCorrelation2d.inputImage
// Property of the inputKernelImage parameter.CudaCrossCorrelation2d.inputKernelImage
// Property of the correlationMode parameter.CudaCrossCorrelation2d.correlationMode
// Property of the tilingMode parameter.CudaCrossCorrelation2d.tilingMode
// Property of the tileSize parameter.CudaCrossCorrelation2d.tileSize
// Property of the cudaContext parameter.CudaCrossCorrelation2d.cudaContext
// Property of the outputImage parameter.CudaCrossCorrelation2d.outputImage
// Property of the outputMeasurement parameter.CudaCrossCorrelation2d.outputMeasurement
// Method to launch the command.Execute()
Parameters
Parameter Name
Description
Type
Supported Values
Default Value
inputImage
The input grayscale image.
Image
Grayscale
nullptr
inputKernelImage
The correlation kernel.
Image
Grayscale
nullptr
correlationMode
The normalization mode for correlation.
DIRECT
Direct correlation (no normalization).
MEAN
Mean normalized correlation (luminosity).
Enumeration
DIRECT
tilingMode
The way to manage the GPU memory.
NONE
The entire input image is transferred to the GPU memory.
If the total input, intermediate and output data size exceed the GPU memory, the computation will fail.
USER_DEFINED
The input image is processed by tiles of a predefined size.
Enumeration
NONE
tileSize
The tile width and height in pixels. They must be greater than or equal to the correlation kernel width and height. This parameter is used only in USER_DEFINED tiling mode.
Vector2u32
Any value
{1024, 1024}
cudaContext
CUDA context information.
CudaContext
nullptr
outputImage
The output correlation image. Its dimensions are forced to the same values as the input. Its data type is forced to floating point.
The entire input image is transferred to the GPU memory.
If the total input, intermediate and output data size exceed the GPU memory, the computation will fail.
USER_DEFINED
The input image is processed by tiles of a predefined size.
enumeration
NONE
tile_size
The tile width and height in pixels. They must be greater than or equal to the correlation kernel width and height. This parameter is used only in USER_DEFINED tiling mode.
vector2u32
Any value
[1024, 1024]
cuda_context
CUDA context information.
cuda_context
None
output_image
The output correlation image. Its dimensions are forced to the same values as the input. Its data type is forced to floating point.
The entire input image is transferred to the GPU memory.
If the total input, intermediate and output data size exceed the GPU memory, the computation will fail.
USER_DEFINED
The input image is processed by tiles of a predefined size.
Enumeration
NONE
tileSize
The tile width and height in pixels. They must be greater than or equal to the correlation kernel width and height. This parameter is used only in USER_DEFINED tiling mode.
Vector2u32
Any value
{1024, 1024}
cudaContext
CUDA context information.
CudaContext
null
outputImage
The output correlation image. Its dimensions are forced to the same values as the input. Its data type is forced to floating point.