clc; clear; close all;

%% setup MatConvNet and complie CPU code
% UNCOMMENT it for the first run.
% run(fullfile(fileparts(mfilename('fullpath')), 'matconvnet-1.0-beta22',...
%    'matlab', 'vl_compilenn.m')) ; 

run(fullfile(fileparts(mfilename('fullpath')), ...
   'matconvnet-1.0-beta22', 'matlab', 'vl_setupnn.m')) ;

%% initialization with pretrained models
distortionType = {'JP2K', 'JPEG', 'WN', 'BLUR', 'PRISTINE'};
net = MEON_init('disTypeNum', numel(distortionType)) ; 
preTrain = load('./released_weights/LIVE.mat');

for i = 1 : numel(preTrain.net.params)
    net.params(i).value = preTrain.net.params(i).value;
end

%% MEON computation
numImg = 4;
inputSize = 256;

score = zeros(numImg, 1);
type = zeros(numImg, 1);
figure;
for i = 1 : numImg
   I = single(imread(['./test_images/' num2str(i) '.bmp']));
   [score(i), type(i)] = MEON(I, net, inputSize); 
   subplot(2, 2, i), imshow(uint8(I)), title(sprintf('MEON = %3.3f, Type = %s', score(i), distortionType{type(i)}));
end

