CheckForPatternInImage.m is a simple Matlab script that detects a pattern (A) in an image (B) using the corr2 function.
The "corr2" function in matlab (R = corr2(A,B)) proves to be very useful for pattern recognition in image processing.
This function can be used to analyze two 2-dimensional images of the same size based on their similarity.
First, both images need to be converted to 𝑛 𝑥 𝑚 -sized arrays.
It should be noted that the arrays must be of the same dimension in order to be processed further.
With the parameters (A) and (B) passed to the "corr2(..,..)" function, the correlation coefficient R is returned as result.
The correlation coefficient R represents the similarity between (A) and (B) by setting the relation of the respective pixel intensity in relation to the average pixel intensity of the whole image.
Hence, the corr2 function represents the following equation to determine the correlation coefficient R:
According to the equation R lies between 0 and 1; Where R = 0 means that there is no correlation and R = 1 indicates the maximum strengthof the relationship.
(see: [1] & [2])
The following flowchart briefly shows the structure of the Matlab script.
Case 1 - correct pattern recognition:
Case 2 - correct pattern recognition with modified pattern:
Case 3 - misleading pattern recognition:
Case 4 - incorrect pattern recognition:
Not perfect, but done.
Matlab - Required: Image Processing