ImageProcessing.correlate

giant.image_processing:

ImageProcessing.correlate(image, template)[source]

This method generates a cross correlation surface between template and image.

The method applies the correlation function specified in the correlator attribute. The returned 2D array in general will be the same size as the image (though this is controlled by the correlator attribute) where each element will represent the correlation score between the template and the image when the center of the template is aligned with the corresponding element in the image. Therefore, to get the location of a template in an image one would do

>>> from giant.image_processing import ImageProcessing
>>> import numpy
>>> ip = ImageProcessing()
>>> local_image = numpy.random.randn(200, 200)
>>> local_template = local_image[30:60, 45:60]
>>> surf = ip.correlate(local_image, local_template)
>>> temp_middle = numpy.floor(numpy.array(local_template.shape)/2)
>>> template_point = numpy.array([0, 0])  # upper left corner
>>> template_point - temp_middle + numpy.unravel_index(surf.argmax(), surf.shape)
array([30., 45.])
Parameters:
  • image (ndarray) – The image to be matched against

  • template (ndarray) – The template to find in the image

Returns:

The normalized correlation surface

Return type:

ndarray