Character Recognition with MLP

    0
    34

    Introduction

    This is simple code for “English Character Recognition” with MLP Neural Network (Multi Layer Perceptron) with more than 80% performance and you can improve it by setting more inputs.

    Using the Code

    For using this code, it’s better to know how it works.

    There are some function named input, convert, testall, tester.

    In script “Main“, we run this code.

    With function “inputpic()“, we get all of our resources that here is 9*7 pictures of the English alphabet (i,m,n,t,v,w,y)

    %% Load Images i= inputpic();

    In input function, we get each picture and convert it to binary data in one column with function whose name is “convert“.

    I1 = imread('./pics/i1.png'); I2 = imread('./pics/i2.png'); I3 = imread('./pics/i3.png'); I1 = convert(I1); I2 = convert(I2); I3 = convert(I3);

    in function input:

    function out = convert(pic) pic = rgb2gray(pic); %change the picture to gray picture pic = im2bw(pic); %%change the picture to black/white picture(binery picture) pic = pic'; pic = pic(:); out = pic; end

    Tip: We didn’t extract any features from pictures and our data is binary pitures data in one column.

    0” means black pixels and “1” is white pixels.

    At the end of input function, we collect all pictures data that set in one column in one matrix.

    M = [I1 I2 I3 M1 M2 M3 N1 N2 N3 T1 T2 T3 V1 V2 V3 W1 W2 W3 Y1 Y2 Y3];

    Now get back to the Main script.

    t is target that shows which number is what character.

    For example, (0,0,0) means character “i“.

    %% Load Images and Set Target i= inputpic(); t = [ 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1; 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1; 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0]; %target: i i i m m m n n n t t t v v v w w w y y y

    After that, we should train our network by input data and targets.

    We use the Multi Layer Perceptron network for our machine learning.

    Train the data and targets with MLP with 100 hidden layers.

    %% Train mlp mlp = newff(i,t,100); mlp = train(mlp,i,t);

    Test the number “i” in this example:

    p = mlp(test);

    Network gives us the number between 0 and 1 and we should normalize it to 0 and 1 number.

    Normalize the answer by threshold: 0.5:

    p=abs(p); k=0; for k=1:3 if(p(k)>0.5) p(k)=1; else p(k)=0; end end

    The performance of this network is more than 80%.

    LEAVE A REPLY