%simualte cnn
clear all;
clc;
close all;
%just for sure

options = odeset('RelTol',1.0E-0,'AbsTol', 1.0E-0,'MaxStep', 1.0E-0);

Max_time = 7;


%define the inputs
%A=[0 0 0; 0 2 0; 0 0 0];
%B=[0 0 0; 0 0 0; 0 0 0];
%P.Z=-0.4;

A=[0 0 0; 0 1 0; 0 0 0];
B=[-1 -1 -1; -1 8 -1; -1 -1 -1];
P.Z=-1;


P.A=reshape(A,1,9);
P.B=reshape(B,1,9);

%read input
%P.Input=ImgToCNN('gray.bmp');
P.Input=ImgToCNN('Spot.BMP');

%image size
P.SizeX=size(P.Input,1);
P.SizeY=size(P.Input,2);

%laod initial state
InitState=1.*P.Input;
%InitState=zeros(P.SizeX,P.SizeY);

[t,X] = ode45(@cell_equation,[0 Max_time],InitState,options,P);

%show the image
out=reshape(X,size(t,1),P.SizeX,P.SizeY);
%cut off the border
img=reshape(out(size(t,1),:,:),P.SizeX,P.SizeY);
ShowCNN(img);


