cnn_setenv

mCNN.TemGroup='temlib_plus';

pic = lbmp2cnn('peppers_scratched.bmp');
scratch = lbmp2cnn('scratch.bmp');

%% Median filter
mCNN.INPUT1 = 1.* pic;
mCNN.INPUT2 = 1.* pic;
mCNN.STATE  = 1.* pic;

loadtem('MEDIAN');
mCNN.Boundary=2;
mCNN.TimeStep=0.02;
mCNN.IterNum=50;
runtem;

median_filtered = mCNN.OUTPUT;

%% Scratch contour

% Erosion
mCNN.INPUT1 = 1.* scratch;
mCNN.INPUT2 = 1.* scratch;
mCNN.STATE = zeros(size(scratch));
% STATE doesn't matter

loadtem('EROSION');
mCNN.Boundary=2;
mCNN.TimeStep=0.2;
mCNN.IterNum=100;
runtem;

erosed = mCNN.OUTPUT;

% LOGDIF
mCNN.INPUT1 = 1.* erosed;
mCNN.INPUT2 = 1.* erosed;
mCNN.STATE = scratch;

loadtem('LOGDIF');
mCNN.Boundary=2;
mCNN.TimeStep=0.02;
mCNN.IterNum=50;
runtem;

contour = mCNN.OUTPUT;

%% Scratch pixel number

mCNN.INPUT1 = 1.* erosed;
mCNN.INPUT2 = 1.* erosed;
mCNN.STATE = scratch;

loadtem('LOGDIF');
mCNN.Boundary=2;
mCNN.TimeStep=0.02;
mCNN.IterNum=50;
runtem;

contour = mCNN.OUTPUT;


%% show result
subplot(131); cnnshow(mCNN.INPUT1);
title('Input')
subplot(132); cnnshow(mCNN.INPUT1);
title('Initial')
subplot(133); cnnshow(contour);
title('Result')