Showing posts with label Neural Network. Show all posts
Showing posts with label Neural Network. Show all posts

Sunday, 4 August 2013

Gesture Recognition using Neural Network in MATLAB Code Part 3

preprocess_gesture.m 

If you have not seen previous post then please go through it first then come back   go to Previous Part


Create a Menu

clc
F = MENU('Choose a database set','Test Set','Train Set'); 
if F==1
K = MENU('Choose a file','Test O');

FOR TESTING A DATASET

if K == 1
    loop=5 
    for i=1:loop 
       string = ['test\O\' num2str(i) '.tif']; 
       Rimages{i} = imread(string); 
    end 

 end 
 end 
end;

FOR TRAINING


if F==2 
    loop=3    %Set loop to 3. All train sets have 3 images 
    L = MENU('Choose a file','Train O'); 
if L == 1 

    for i=1:loop 
    string = ['train\O\' num2str(i) '.tif']; 
    Rimages{i} = imread(string); 
    end
end 
end 

Now do what I am doing here


T{i}=imresize(Timages{i},[150,140]); 

    x = [0 -1 1];                               
    y = [0 1 -1]';

dx{i} = convn(T{i},x,'same');
dy{i} = convn(T{i},y,'same');
gradient{i} = dy{i} ./dx{i};
theta{i} = atan(gradient{i});
cl{i}= im2col(theta{i},[1 1],'distinct');
 N{i} = (cl{i}*180)/3.14159265359; .
c1{i}=(N{i}>0)&(N{i}<10 div="" nbsp="">
    s1{i}=sum(c1{i}); 

    c2{i}=(N{i}>10.0001)&(N{i}<20 div="" nbsp="">
    s2{i}=sum(c2{i}); 

    c3{i}=(N{i}>20.0001)&(N{i}<30 div="" nbsp="">
    sum(c3{i}); 
    s3{i}=sum(c3{i}); 

    c4{i}=(N{i}>30.0001)&(N{i}<40 div="" nbsp="">
    sum(c4{i}); 
    s4{i}=sum(c4{i}); 

    c5{i}=(N{i}>40.0001)&(N{i}<50 div="" nbsp="">
    sum(c5{i}); 
    s5{i}=sum(c5{i}); 

    c6{i}=(N{i}>50.0001)&(N{i}<60 div="" nbsp="">
    sum(c6{i}); 
    s6{i}=sum(c6{i}); 

    c7{i}=(N{i}>60.0001)&(N{i}<70 div="" nbsp="">
    sum(c7{i}); 
    s7{i}=sum(c7{i}); 

    c8{i}=(N{i}>70.0001)&(N{i}<80 div="" nbsp="">
    sum(c8{i}); 
    s8{i}=sum(c8{i}); 

    c9{i}=(N{i}>80.0001)&(N{i}<90 div="" nbsp="">
    sum(c9{i}); 
    s9{i}=sum(c9{i}); 

    c10{i}=(N{i}>90.0001)&(N{i}<100 div="" nbsp="">
    sum(c10{i}); 
    s10{i}=sum(c10{i}); 

    c11{i}=(N{i}>-89.9)&(N{i}<-80 div="" nbsp="">
    sum(c11{i}); 
    s11{i}=sum(c11{i}); 
    c12{i}=(N{i}>-80.0001)&(N{i}<-70 div="" nbsp="">
    sum(c12{i}); 
    s12{i}=sum(c12{i}); 

    c13{i}=(N{i}>-70.0001)&(N{i}<-60 div="" nbsp="">
    sum(c13{i}); 
    s13{i}=sum(c13{i}); 

    c14{i}=(N{i}>-60.0001)&(N{i}<-50 div="" nbsp="">
    sum(c14{i}); 
    s14{i}=sum(c14{i}); 

    c15{i}=(N{i}>-50.0001)&(N{i}<-40 div="" nbsp="">
    sum(c15{i}); 
    s15{i}=sum(c15{i}); 

    c16{i}=(N{i}>-40.0001)&(N{i}<-30 div="" nbsp="">
    sum(c16{i}); 
    s16{i}=sum(c16{i}); 

    c17{i}=(N{i}>-30.0001)&(N{i}<-20 div="" nbsp="">
    sum(c17{i}); 
    s17{i}=sum(c17{i}); 

    c18{i}=(N{i}>-20.0001)&(N{i}<-10 div="" nbsp="">
    sum(c18{i}); 
    s18{i}=sum(c18{i}); 

    c19{i}=(N{i}>-10.0001)&(N{i}<-0 .0001="" div="" nbsp="">
    sum(c19{i}); 
    s19{i}=sum(c19{i}); 

    D{i}= [s1{i} s2{i} s3{i} s4{i} s5{i} s6{i} s7{i} s8{i} s9{i} s10{i} s11{i} s12{i} s13{i} s14{i} s15{i} s16{i} s17{i} s18{i} s19{i}]; 

close(w);

Guys thanks for visiting my blog,Have fun :)


This is the end of gesture recognition


Please LIKE and COMMENT...


Gesture Recognition using Neural Network in MATLAB Code Part 2

neuralnetwork_gesture.m

Go to First Part                             Go to Next Part



echo on
clc
pause
clc

Store the training informations in a test file

fid = fopen('train.txt','rt');
P1 = fscanf(fid,'%f',[19,inf]);
P=P1;

Open some text file using code to write and fetch the required information about image.


fid = fopen('testO.txt','rt');
TS1 = fscanf(fid,'%f',[19,inf]);

%(As here we are only testing alphabet 'O')

fid = fopen('target8.txt','rt');
T = fscanf(fid,'%f',[8,inf]);

It has been found that the optimal number of neurons for  the hidden layer is 85

S1 = 85;
S2 = 5;

Now we have to initialize pre-processing layer

[W1,b1] = initp(P,S1);

We also have to initialize learning layer

 [W2,b2] = initp(S1,T);

pause 

NOW TRAIN THE NETWORK


A1 = simup(P,W1,b1);
TP = [1 500]; 
pause
clf reset
figure(gcf)

% resize the frame size
setfsize(600,300);

[W2,b2,epochs,errors] = trainp(W2,b2,A1,T,TP);

pause
clc 

ploterr(errors); 


pause

M = MENU('Choose a file resolution','Test O');    %as we are only showing 'O',you can add more
if M == 1 
 TS = TS1;
else 
 disp('Wrong input');

a1 = simup(TS,W1,b1);        

a2 = simup(a1,W2,b2)      

echo off 

Next part will be posted in next Post,Thanks for visiting have fun

Gesture Recognition using Neural Network in MATLAB 


Gesture Recognition using Neural Network in MATLAB Code

Hi guys,many people were requesting for gesture recognition code so here it is ...
Well for any recognition system there are some simple common states what we also followed here they are:


1. First you have to have data set.Which you have to prepare or download from any website according to your demand.Like you want to want to recognize an alphabet 'O'.Then you have to provide particular data set for 'O'.


Like this :



Okey this is only one picture but I recommend at least 5 pictures you have to give to recognize a gesture.


2. Now give matlab access to the data sets providing particular path of the folder on your system,it is better to make different folder for different alphabet sample.


3. Now you have to train the network.I will show you how to do it in later part.It is the most important part,here you are making your network understand that " ANY IMAGE LIKE-THIS IS ALPHABET 'O' "


4.Here you need to provide an algorithm that will set such a threshold value that will decide whether the test image is 'O' or NOT.


5.Now you need some more sample of 'O' to test the network whether it is coming fine.


6.Well that is it. I will give you the sample code in my next post so that it will be easy for you to implement.


Proceed to Next Part


Thanks a lot for visiting have fun.









Saturday, 23 February 2013

Bestfitness matlab code using neural network


    clc;
    a= [39.8878 39.9947 39.9544 40.0285 39.9263 40.0013 40.9078 39.7623 40.9278];
    b=[0.6016 0.6016 0.6045 0.6074 0.6067 0.6074 0.6052 0.5998 0.6056] ;
    c=[100 100 100 100 100 100 100 100 100];
    y=a+ b.*c;
    I=[a; b; c];
    T=y;
    R=[0 1000; 0 1000 ; 0 1000];
    S=[5 1];
    net = newff([0 1000;0 1000 ;0 1000],[4 1],{'tansig','purelin'});
    O=[100.0439 100.5907 100.4028 100.7729 100.5963 100.7457 100.5964 99.7375 100.6877];
    net=train(net,I,O);
    O1=sim(net,I);
    plot(1:9,O,1:9,O1);
     net.IW{1}
     net.LW{2,1}
     BestFitness=sim(net,[39.8595 0.6023 100]');