Where to nget templates
3 views (last 30 days)
Show older comments
%original image was selected [FileName,b] = uigetfile('*.jpg'); handles.fullPath= [b FileName] ; a =imread (handles.fullPath); %size image 648x486 imshow(a)
b=im2bw(a);
filter = [ 0 0 0 -1 -1 -1 0 0 0 ; 0 -1 -1 -3 -3 -3 -1 -1 0; 0 -1 -3 -3 -1 -3 -3 -1 0; -1 -3 -3 6 13 6 -3 -3 -1; -1 -3 -1 13 24 13 -1 -3 -1; -1 -3 -3 -6 13 6 -3 -3 -1; 0 -1 -3 -3 -1 -3 -3 -1 0; 0 -1 -1 -3 -3 -3 -1 -1 0; 0 0 0 -1 -1 -1 0 0 0 ]; % [make analysis]
imshow(b) E = entropyfilt(b); Eim = mat2gray(E); imshow(Eim);
BW1 = im2bw(Eim, .8); imshow(BW1);
BWao = bwareaopen(BW1,2000); %dilation-opening %[make analysis] imshow(BWao); nhood = true(10); closeBWao = imclose(BWao,nhood);%dilation& erosion-closing imshow(closeBWao) roughMask = imfill(closeBWao,'holes'); %[make analysis] imshow(roughMask);
I2 = b; I2(roughMask) = 0; imshow(I2); E2 = entropyfilt(I2); %filteration E2im = mat2gray(E2); imshow(E2im); BW2 = im2bw(E2im,graythresh(E2im)); imshow(BW2)
mask2 = bwareaopen(BW2,1000); imshow(mask2); texture1 = b; texture1(~mask2) = 0; texture2 = b; texture2(mask2) = 0;
imshow(texture1); imshow(texture2);
%image extraction c=imcrop(texture2,[150 205 350 80]); % [make analysis] imshow(c) d = bwareaopen(~c,30); pause(1) imshow(d);
[L, Ne]=bwlabel(~d); % Measure properties of image regions propied=regionprops(L,'BoundingBox'); hold on % Plot Bounding Box for n=1:size(propied,1) rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2) hold off pause (0.5) end hold off pause (1)
for n=1:Ne [r,c] = find(L==n); n1=~d(min(r):max(r),min(c):max(c)); imshow(~n1); pause(0.5) end
d = bwareaopen(~d,40);
%Storage matrix word from image word=[ ]; re=d; %Opens text.txt as file for write fid = fopen('text.txt', 'wt'); % Load templates load templates global templates % Compute the number of letters in template file num_letras=size(templates,2); while 1 %Fcn 'lines' separate lines in text [fl, re]=lines(re); imgn=fl; %Uncomment line below to see lines one by one %imshow(fl);pause(0.5) %----------------------------------------------------------------- % Label and count connected components [L, Ne] = bwlabel(imgn); for n=1:Ne [r,c] = find(L==n); % Extract letter n1=imgn(min(r):max(r),min(c):max(c)); % Resize letter (same size of template) img_r=imresize(n1,[42 24]); %Uncomment line below to see letters one by one %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) % Clear 'word' variable word=[ ]; %*When the sentences finish, breaks the loop if isempty(re) %See variable 're' in Fcn 'lines' break end end fclose(fid); %Open 'text.txt' file winopen('text.txt')
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!