Please tell me matlab code for handwritten characters recognition using template matching.

1 view (last 30 days)
I am working on handwritten recognition. Kindly help me in this matter please.....
  1 Comment
MONIKA SAINI
MONIKA SAINI on 14 Feb 2015
Edited: Walter Roberson on 14 Dec 2015
I RUN THIS CODE FOR TEMPLATE MATCHING USING CORRELATION. BUT THIS IS SHOWING ERROR.
Error in ==> Untitled at 42
subplot(1,2,2), imshow(OriDu(x:x+TempH, y:y+TempW, :)),title('Segment of the similar part')
??? Index exceeds matrix dimensions.
Original = imread('C:\Users\abcd\Desktop\scanned\scanned data\scanned data\template y\cross.jpg'); % Read original image
Template = imread('C:\Users\abcd\Desktop\scanned\scanned data\scanned data\y\20.jpg'); % Read template image
OriDu = im2double(Original); % convert original image
TempDu = im2double(Template); % convert template
OriH = size(Original, 1); %height of the Original image
OriW = size(Original, 2); %width of the Original image
OriD = size(Original, 3); %colour depth
TempH = size(Template, 1); %height of the Template image
TempW = size(Template, 2); %width of the Template image
TempD = size(Template, 3); %colour depth
TempDu = reshape(TempDu, TempH*TempW, 3);
corr = 0; % to check the best correlation found
%%two for loops to go through the original image.
for i = 1:OriH-TempH
for j = 1:OriW-TempW
% take a segment of the original image( same size as the template size)
segment = OriDu(i: (i - 1) + TempH, j: (j - 1) + TempW, :);
segment = reshape(segment, TempH*TempW, 3);
output = corr2(TempDu, segment);
if output > corr
corr = output;
x = i;
y = j;
end
end
end
figure;
subplot(1,2,1), imshow(Template), title('Template');
subplot(1,2,2), imshow(OriDu(x:x+TempH, y:y+TempW, :)),title('Segment of the similar part')

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 14 Dec 2015
In your loop finding the largest corr2(), you are using a slice of OriDU that is TempH high by TempW wide. However when you get to the end to plot, you are extracting a slide that is TempH+1 high by TempW+1 wide. Your loop does the indexing correctly, remembering to subtract 1 from the upper end of the range, and it is your imshow() call that is incorrect.

Community Treasure Hunt

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

Start Hunting!