how bounding box detect letter in binary image

1 view (last 30 days)
clc
clear all
close all%% Read Image
Inputimage=imread('manhoos.jpg');
%Inputimage=imread('DMM3.png');
%% Show image
Inputimage=imcrop(Inputimage)
figure(1)
imshow(Inputimage);
title('INPUT IMAGE WITH NOISE')
x=[];
%% Convert to gray scale
if size(Inputimage,3)==3 % RGB image
Inputimage=rgb2gray(Inputimage);
end
%% Convert to binary image
threshold = graythresh(Inputimage);
Inputimage =~im2bw(Inputimage,threshold);
word=[ ];
%% Remove all object containing fewer than 30 pixels
Inputimage=im2bw(Inputimage)
Inputimage1 = bwareaopen(Inputimage,10);
% Inputimage2 = bwmorph(Inputimage1,'remove');
% Inputimage = bwmorph(Inputimage2,'skel',Inf);
re=Inputimage1;
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(Inputimage);
for n=1:Ne
[r,c] = find(L==n);
n1=imgn(min(r):max(r),min(c):max(c));
% Resize letter (same size of template)
figure
imshow(n1);pause(0.5)
% img_r=imresize(n1,[42 24]);
% % Sort boxes by image height
% s = regionprops(n1,'BoundingBox');e
% bboxes = vertcat(s(:).BoundingBox);
% [~,ord] = sort(bboxes(:,2));
% bboxes = bboxes(ord,:);
% % Pre-process image to make letters thicker
% BW = imdilate(n1,strel('disk',1));
% % Call OCR and pass in location of words. Also, set TextLayout to 'word'
% ocrResults = ocr(n1,bboxes,'CharacterSet','-.0123456789','TextLayout','word');
% words = {ocrResults(:).Text}';
% words = deblank(words)
%Uncomment line below to see letters one by one
% figure
% 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
end
pause(1);

Answers (0)

Categories

Find more on Modify Image Colors in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!