
function [ net ] = get_test_ms(varargin)
warning off;
addpath(genpath('src\'));
addpath(genpath('Simulate_Data\'));

% cpu and gpu settings 
opts.idx_gpus = 0; % 0: cpu
opts.num_images = 32; % images to be generated
% for j = 1:100
opts.matconvnet_path = 'matconvnet-1.0-beta24/matlab/vl_setupnn.m';

opts.net_path = 'net/net-epoch-81.mat'; 
% opts.net_path = strcat('net/net-epoch-',num2str(j),'.mat') ;

sigma     =  00;
variance       = 15;
amplify        = 000000;
stripe_min     = -10;        %%% min value
stripe_max     = 10;         %%% max value
showResult  = 0;

opts = vl_argparse(opts, varargin);

run(opts.matconvnet_path);

%% load network
net = load(opts.net_path);
net = net.net(1); % idx 1: Generator, 2: Discriminator
net = dagnn.DagNN.loadobj(net);
net.mode = 'test';

if opts.idx_gpus >0
%     gpuDevice()
    net.move('gpu');
end

% folderTest  = 'testsets\LWIR'; %%% test dataset
folderTest  =  'testsets\Middle Wave IR';
ext         =  {'*.jpg','*.png','*.bmp','*.tif','*.tiff'};
filePaths   =  [];
for i = 1 : length(ext)
    filePaths = cat(1,filePaths, dir(fullfile(folderTest,ext{i})));
end

%%% PSNR and SSIM
PSNRs = zeros(1,length(filePaths));
SSIMs = zeros(1,length(filePaths));
for i = 1:length(filePaths)
    %%% read images
    label = imread(fullfile(folderTest,filePaths(i).name));
    if size(label,3) == 3
       label = rgb2gray(label);
    end

%     label  = label(50:529,71:550);
%     label  = label(150:405,150:405);
    label = im2double(label);
%     label = mat2gray(label);
    randn('seed',0);
    rand('seed',0);

%     Bias_field = zeros(size(label));
    Bias_field = amplify * fspecial('gaussian', size(label), variance) / 256;
       
    stripe  = single(repmat((stripe_max - stripe_min).*rand(1,size(label,2)) + stripe_min,size(label,1),1)/255);
    noise   = label +  Bias_field +  stripe + single(sigma/255*randn(size(label)));

    if opts.idx_gpus >0,   noise = gpuArray(noise);    end
    net.eval({'input',noise});
%     im_out = gather(net.vars(net.getVarIndex('conv27')).value);
    im_out = gather(net.vars(net.getVarIndex('conv34')).value);
%     output = im_out;
    output = noise - im_out;
 
    if opts.idx_gpus 
        output = gather(output);
        noise  = gather(noise);
    end  

    %%% calculate PSNR and SSIM
    [PSNRCur, SSIMCur] = Cal_PSNRSSIM(im2uint8(label),im2uint8(output),0,0);

    if showResult
        figure, imshow(cat(2,im2uint8(label),im2uint8(noise),im2uint8(output)));
        title([filePaths(i).name,'    ',num2str(PSNRCur,'%2.2f'),'dB','    ',num2str(SSIMCur,'%2.4f')])
        drawnow;
        pause(pauseTime)
    end
    PSNRs(i) = PSNRCur;
    SSIMs(i) = SSIMCur;
end
disp([mean(PSNRs),mean(SSIMs)]);
% aa(j,1) = [mean(PSNRs)];
% aa(j,2) = [mean(SSIMs)];
% end
% k =1;
