-
Notifications
You must be signed in to change notification settings - Fork 2
/
RunNeuralNetworks.m
65 lines (57 loc) · 1.13 KB
/
RunNeuralNetworks.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%Neural Networks Codes will be run on this part
% tic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear all
pic=imread('self_writing\3.jpg');
pic1=imread('8.png');
pic1=rgb2gray(pic1);
% pic=255-pic;
[a,b]=size(pic1);
for i=1:1:a
for j=1:1:b
if pic1(i,j)==0
up=i;
break
end
end
end
for i=a:-1:1
for j=1:1:b
if pic1(i,j)==0
down=i;
break
end
end
end
for j=1:1:b
for i=1:1:a
if pic1(i,j)==0
left=j;
break
end
end
end
for j=b:-1:1
for i=1:1:a
if pic1(i,j)==0
right=j;
break
end
end
end
pic=pic1(down:up,right:left);
imshow(pic)
pic=imresize(pic,[28 28]);
% size(pic);
pic1=1-double(reshape(pic,784,1))/255;
[m,n]=train(10, 3, [784, 30, 10]);
[A,Z]=feedforward(pic1,m,n);
aa=A{3}(:,1);
i = find(aa==max(aa));
i=i-1;
fprintf('The Handwritten Number is %d\n',i);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
toc
clc
clear all