Correlation & Convolution
Fundamental Operation in Computer Vision
• Correlation
• Convolution
Correlation
• The mathematical operation used to measure
the similarity between two images.
• In image processing, a kernel, convolution
matrix, or mask is a small matrix used for
blurring, sharpening, embossing, edge
detection, and more.
Mathematical Formula
• I – image
• F – Filter or Kernel or Mask
• (x,y) – position of an image
• (i,j) – position of a filter
• Mathematical formula for 2D images
Steps in Correlation
• 1. Slide the center of the correlation kernel on
the image
• 2. Multiply each weight in the correlation
kernel by the pixel in the image
• 3. Sum these products
Example
Linear Filter Based on Correlation
• Blur Filter
• import cv2
import matplotlib.pyplot as plt
import numpy as np# read image
src = cv2.imread('src.png', 0)# prepare the filter
kernel = [[0,0,0], [0,1,0], [0,0,0]]# apply kernel to the original image
dst = cv2.filter2D(src, -1, np.array(kernel))# concatenate images
horizontally
result = np.concatenate((src, dst), axis=1)
cv2.imwrite('result.png', result)
Convolution Filtering
• In image processing, convolution is a process
by which we transform an input image by
applying a kernel over it in a pixel-wise
fashion.
• When the convolution mask operates on a
particular pixel, then it performs the action by
considering that pixel and its neighbouring
pixels and the result is returned to that one
particular pixel.
Mathematical Formula
Steps
Comparison