Corr2 between two cells (one is a mat file containing template images and another is a cell which has the extracted characters from an image)

3 views (last 30 days)
I am trying to develop a recogntion algorithm and I have managed to create a mat file with some template letter and in my main code, I have managed to extracted the characters that I want using bounding boxes. I have cropped the bounding boxes using imcrop and created a set of images known as extracted characters. I have saved these extracted characters in a cell(1x14). In my code I have loaded the template and the cell array of the template is 1x24.
I am trying to use corr2 and a loop that goes through the 14 extracted characters and find the matched version in the template cell.
with my current code I can only find the match for the first extracted character. I dont know how to achieve the same thing for the other extracted characters.
Thanks for your help and time in advance.
CharTemp = load('CharTemplates.mat');
CTemplate = CharTemp.CharTemplates(:,end);
comp = [];
for n = 1 : length(CTemplate)
sem{n} = corr2(ExCharSaved{n}, CTemplate{:}); %ExCahrSaved is a cell created prior in the code that has all the extracted characters in it
% Record the value of correlation for each template's character.
comp=[comp sem{n}];
vd{n} = find(comp==max(comp));

Accepted Answer

Sahil Jain
Sahil Jain on 31 Aug 2021
Hi Helia. I’m assuming that the "extracted characters" and "template letters" are both matrices having the same dimensions. I understand that for each "extracted character", you want to find out which "template letter" has the highest correlation. In this case, I would suggest you use a nested for loop – the outer loop is for the "extracted characters", and the inner loop is for the "template letters". Please have a look at the code below. I have tried to keep the variable names the same as yours. The cell array “vd” will contain the index of the template letter with the highest correlation for each of the 14 "extracted characters".
vd = {};
for i = 1 : length(ExCharSaved)
comp = [];
for j = 1 : length(CTemplate)
comp = [comp, corr2(ExCharSaved{i}, CTemplate{j})];
vd{i} = find(comp==max(comp));

More Answers (0)

Community Treasure Hunt

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

Start Hunting!