-
Notifications
You must be signed in to change notification settings - Fork 1
/
char2.m
44 lines (34 loc) · 841 Bytes
/
char2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
%% Character Recognition Example (II):Automating Image Pre-processing
%% Read Image
I = imread('sample.bmp');
%I = imread('Test14.bmp');
imshow(I)
%% Convert to grayscale image
Igray = rgb2gray(I);
imshow(Igray)
%% Convert to binary image
Ibw = im2bw(Igray,graythresh(Igray));
imshow(Ibw)
%% Edge detection
Iedge = edge(uint8(Ibw));
imshow(Iedge)
%% Morphology
% * *Image Dilation*
se = strel('square',2);
Iedge2 = imdilate(Iedge, se);
imshow(Iedge2);
% * *Image Filling*
Ifill= imfill(Iedge2,'holes');
imshow(Ifill)
%% Blobs analysis
[Ilabel num] = bwlabel(Ifill);
disp(num);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Ibox = reshape(Ibox,[4 50]);
imshow(I)
%% Plot the Object Location
hold on;
for cnt = 1:50
rectangle('position',Ibox(:,cnt),'edgecolor','r');
end