Keywords: front-page

## Lab: Correlation

[Exercises] [Workspace]

Purpose: The purpose of this lab exercise is to experiment with template matching, correlation, and normalized correlation using spatial convolution.

Activities:

1. Read and display the image $DIP/data/gull.kdf. Convert it to floating point using the operator Convert Type.

   1. Glyphs:Input/Output:Data Files:User defined
   2. Glyphs:Visualization:Non-Interactive Display:Display Image
   3. Glyphs:Data Manip:Data Conversion:Convert Type

2. Extract a small (10x10) pattern from the image using the Extract operator. Determine the coordinates of the region you wish to extract by moving the cursor over the pattern in the displayed image. Display the extracted region (first expand it by a factor of 10).

   1. Glyphs:Data Manip:Size & Region Operators:Extract
   2. Glyphs:Data Manip:Size & Region Operators:Expand
   3. Glyphs:Visualization:Non-Interactive Display:Display Image

3. Perform the correlation between the image and the pattern using the LinearOp (Linear Operator) operator. Set its parameter option to perform the "Correlation". Display the result with the Display Image glyph.

   1. Glyphs:Arithmetic:Linear Transforms:LinearOp (Linear Operator)
   2. Glyphs:Visualization:Non-Interactive Display:Display Image

4. Use the Statistics operator to find the coordinates of the maximum point of the resulting image. Open the Statistics pane and select the "maximum", and the width and height coordinates of the maximum.

   1. Glyphs:Data Manip:Analysis & Information:Statistics

      Notice that the maximum does not occur where you would expect it to, which is over the pattern that you extracted.

5. Perform the normalized correlation.

   1. Multiply converted $DIP/data/gull.kdf image for it.

      1. Glyphs:Arithmetic:Two Operand Arithmetic:Multiply

   2. Create a constant kernel of value 1 that is the same size as the pattern (10x10) using the Constant operator. Perform correlation between the multiplyed image and this kernel. Set up the LinearOp (Linear Operator) operator as you did in step 3.

      1. Glyphs:Input/Output:Generate Data:Constant
      2. Glyphs:Arithmetic:Linear Transforms:LinearOp (Linear Operator)

   3. Take the square root of the result of the correlation in step B, using the Square Root operator.

      1. Glyphs:Arithmetic:Single Operand Arithmetic:Square Root

   4. Divide the original correlation image (step 3) by the normalization factor image just created, and display the result.

      1. Glyphs:Arithmetic:Two Operand Arithmetic:Divide
      2. Glyphs:Visualization:Non-Interactive Display:Display Image

   5. Find the maximum of the normalized correlation using the Statistics operator as you did in step 4.

      1. Glyphs:Data Manip:Analysis & Information:Statistics

Exercises

1. Perform the same experiment, but in the frequency domain.

Khoros Workspace
Execute the visual program c6s5correlation.wk