function [img,u,state]=falling(img,tf,dtime)
%
% CNN falling membrane template applied to image file.
% 
% Usage: img=falling(filename, tf, dtime);
%
% One can then use img as input to either 
%   edge(img,'canny');   % with normal gaussian smoothing 
% or
%   cannyNoGauss(img,'canny'); 
% .

% control and feedback templates -- tunable
A = template_form([-3.0 1.0 1.0]);
B = template_form([-4.0 1.0 1.0]); 

u = im2double(img);
uu = im2double(max(max(u)));
ul = im2double(min(min(u)));
[uy,ux] = size(u);

% scale it to cnn image range [-1, 1] ??
u = (u-ul)/(uu-ul)*2-1;
x0 = -1*ones(uy,ux);

% gravity -- tunable
I = -0.05 ;

state=viewcnn(A,B,I,x0,u,tf,dtime);
state=pwlsig(state);
img=state+u+1;
figure;imagesc(img);colormap(gray);



