Difference between convolution and correlation in Image processing

24 visualizzazioni (ultimi 30 giorni)
Dear Team,
In our matlab inbuilt function xcorr2 uses convolution operation with rotated mask but in conv2 function it will do normal convolution without any rotation. But as per actual definition, in convoltuion operation there will be 180 degree rotation either in mask or in Image right. But it is contrary in our MATLAB function. Kindly correct me and clear my doubt.
Thanks and Regards,
M.Shanmuga sundari.

Risposte (1)

Diya Tulshan
Diya Tulshan il 18 Lug 2023
Hii Shanmugasundari Mariappan,
I understand that you want a clarity between the xcorr2 and conv2 function.
  1. Convolution: In convolution, the kernel (mask) is flipped both horizontally and vertically before before being applied to the mask or image. This flipping operation is equivalent to a 180-degree rotation of the kernel. MATLAB's 'conv2' function performs this flipped convolution.
  2. Cross-correlation: In cross-correlation, the mask is not rotated, and it is directly applied to the image. MATLAB's 'xcorr2' function calculates the cross-correlation between the mask and the image.
Also, I have mentioned the differnece between the two functions.
  1. 'conv2' function: The conv2 function in MATLAB performs convolution with a flipped (180-degree rotated) kernel. It follows the standard definition of convolution where the kernel is flipped before performing the convolution operation.
  2. 'xcorr2' function: The xcorr2 function in MATLAB performs cross-correlation, not convolution. Cross-correlation does not involve flipping the kernel. It directly applies the kernel to the input signal or image without any rotation.
To summarize the 'conv2' function performs convolution with a flipped kernel, while the 'xcorr2' function performs cross-correlation without any kernel rotation.
Kindly refer to the following links for better understanding:-
  1 Commento
Shanmugasundari Mariappan
Shanmugasundari Mariappan il 19 Lug 2023
Dear Diya Tulshan,
Thank you so much for your clear clarification. Now I understood clearly. I was confused with inbuilt function definitions which is attached below. In the function definition of correlation, we rotated the mask values as in Figure 1. Regarding one dimensional convolution fucntion it is mentioned that convolution of two 1D vector is similar to multiplying two polynomial coffecients as given in Figure 2. Because of these lines I got confused. But in those two function web pages I got clear idea. Thank you.
Thanks and Regards,
M.Shanmuga sundari

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by