Unable to recognize letter O and R

1 view (last 30 days)
Hi, I'm currently doing a project on text recognition by using matlab. Refer code below. However, for some images the program incorrectly recognize 'O' as '0' and 'R' as 'n'. I've already included all the image pre-processing steps and remove the noise present. Can someone please suggest a way on how to correct this error.
%%%%%% Text Recognition
warning off %#ok<WNOFF> % Clear all clc, close all
% Get file from folder [filename, pathname] = uigetfile('*','LOAD AN IMAGE'); %fullimageFileName=fullfile(folder,baseFileName);
% Read image Image=imread(fullfile(pathname,filename));
% Show image figure,imshow(Image) title('ORIGINAL IMAGE');pause(3)
% NOISE REMOVAL - Pre Processing % 1- Gaussian Smoothing Image2 = imgaussfilt(Image,2); figure,imshow(Image2) title('GAUSSIAN APPLIED');pause(3)
%Adjust image intensity 88 PreP1 = imadjust(Image2,[.3 0.5],[]); figure, imshow(PreP1) title('IMAGE INTENSITY ADJUSTED');pause(3)
% 3- Convert to Grayscale if size(PreP1,3)==3 % check if its RGB image convert to grayscale PreP1=rgb2gray(PreP1); %figure, imshow(PreP1) %title('Grayscale Image') end
% 4- Convert to Black and White (thresholding) threshold = graythresh(PreP1); PreP1 =~im2bw(PreP1,threshold); PreP2 = PreP1; %figure, imshow(PreP2) %title('Binary Image')
% Remove all object containing fewer than 30 pixels PreP3 = bwareaopen(PreP2,30); Image3 = PreP3; figure, imshow(Image3) title('Filtered Image');pause(3)
%Storage matrix word from image word=[ ]; re=Image3;
%Opens .txt file to write the extracted text fid = fopen('Text Extracted.txt', 'wt');
% Load templates load templates global templates
% Compute the number of letters in template file num_letras=size(templates,2);
while 1 %separate letter in lines [fl, re]=lines_crop(re); % fl = first line in text; re = remaining imgn2=fl;
figure,imshow(fl);pause(3) %
% Label and count connected components
[L, Ne] = bwlabel(imgn2);
for n=1:Ne
%to get the row and column coordinates of the object labeled 'n'
[r,c] = find(L==n);
% Extract Letter
n1=imgn2(min(r):max(r),min(c):max(c));
% Resize letter (same size of template)
img_r=imresize(n1,[42 24]); %imresize(A,scale) returns img_r that is scale times the size of A.
imshow(img_r);pause(0.5)
%-------------------------------------------------------------------
% Call fcn to convert image to text
letter=read_letter(img_r,num_letras);
% Letter concatenation
word=[word letter];
end
%fprintf(fid,'%s\n',lower(word));%Write 'word' in text file (lower)
fprintf(fid,'%s\n',word);%Write 'word' in text file (upper)
word=[ ];
%*When the sentences finish, breaks the loop
if isempty(re) %See variable 're' in Fcn 'lines'
break
end
end
%Text that has been extracted will be displayed in the 'text.txt' file winopen('Text Extracted.txt')
%read data from .txt file data = textread('Text Extracted.txt', '%s', 'whitespace','');
%text2speech synthesizer convert the data from .txt file to voice TextToSpeech(data);
fclose(fid); clear

Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!