This repository has been archived by the owner on Apr 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added evaluating code referenced in DeepVideoDeblurring.
- Loading branch information
Showing
273 changed files
with
22,041 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
%% Clean | ||
clear | ||
close all | ||
|
||
%% Parameters | ||
date = '1220'; | ||
alignments = {'_nowarp','_homography','_OF'};%{'_nowarp','_homography','_OF'}; | ||
outputDir = 'E:\projects\DeepVideoDeblurring\outImg'; | ||
outputFolderPrefix = [date '_validating_model2_symskip_nngraph2_deeper']; | ||
gtDir = 'E:\projects\DeepVideoDeblurring\dataset\quantitative_datasets'; | ||
global frameExt | ||
frameExt = '.jpg'; | ||
|
||
%% Scan videos | ||
outputFolders = {}; | ||
for alignment = alignments | ||
outputFolders{end+1} = [outputFolderPrefix,alignment{1}]; | ||
end | ||
outputFolders = fullfile(outputDir,outputFolders); | ||
% videoNames = {}; | ||
% for outputFolder = outputFolders | ||
% videoNames{end+1} = dir(outputFolder{1}); | ||
% maskFolders = [videoNames{end}.isdir]; | ||
% videoNames{end} = videoNames{end}(maskFolders); | ||
% videoNames{end} = videoNames{end}(3:end); | ||
% videoNames{end} = {videoNames{end}.name}; | ||
% end | ||
|
||
validset = {'IMG_0030' 'IMG_0049' 'IMG_0021' '720p_240fps_2' 'IMG_0032' ... | ||
'IMG_0033' 'IMG_0031' 'IMG_0003' 'IMG_0039' 'IMG_0037'};% from git rep DeepVideoDeburring | ||
|
||
%% Evaluate PSNR | ||
align2PSNRs = zeros(length(alignments),length(validset)+1); | ||
for iAlignment = 1:length(alignments) | ||
alignment = alignments{iAlignment}; | ||
|
||
%% scan validset frames | ||
frameDirs = scanFrames(outputFolders{iAlignment},gtDir,validset); | ||
|
||
%% evaluate PSNR | ||
for iVideo = 1:size(frameDirs,1) | ||
avgPSNR = 0; | ||
nFrame = size(frameDirs,2); | ||
parfor iFrame = 1:nFrame | ||
gtFrameDir = frameDirs{iVideo,iFrame,1}; | ||
outputFrameDir = frameDirs{iVideo,iFrame,2}; | ||
gt = imread(gtFrameDir); | ||
output = imread(outputFrameDir); | ||
scores = evaluate_align(gt,output,'PSNR'); | ||
avgPSNR = avgPSNR+scores.PSNR; | ||
% scores = metrix_mux(gt,output,'PSNR'); | ||
% avgPSNR = avgPSNR+scores; | ||
end | ||
avgPSNR = avgPSNR/nFrame; | ||
align2PSNRs(iAlignment,iVideo) = avgPSNR; | ||
fprintf('video %d/%d done!\n',iVideo,size(frameDirs,1)) | ||
end | ||
|
||
end | ||
align2PSNRs(:,end) = mean(align2PSNRs(:,1:length(validset)),2) | ||
|
||
%% functions | ||
function frameDirs = scanFrames(outputFolder,gtDir,videoNames) | ||
global frameExt | ||
% for all videos | ||
disp('Scanning frames...'); | ||
frameDirs = {}; | ||
iFrameAll = 1; | ||
for iVideo = 1:length(videoNames) | ||
videoName = videoNames{iVideo}; | ||
outputFrameFolder = fullfile(outputFolder,videoName); | ||
outputFrameNames = dir(fullfile(outputFrameFolder,['*',frameExt])); | ||
outputFrameNames = {outputFrameNames.name}; | ||
gtFrameFolder = fullfile(gtDir,videoName,'GT'); | ||
gtFrameNames = dir(fullfile(gtFrameFolder,['*',frameExt])); | ||
gtFrameNames = {gtFrameNames.name}; | ||
for iFrame = 1:length(outputFrameNames) | ||
frameDirs{iVideo,iFrame,1} = [gtFrameFolder,'/',gtFrameNames{iFrame}]; | ||
frameDirs{iVideo,iFrame,2} = [outputFrameFolder,'/',outputFrameNames{iFrame}]; | ||
iFrameAll = iFrameAll+1; | ||
end | ||
fprintf('Found %d frames, video %d/%d\n',iFrameAll-1,iVideo,length(videoNames)) | ||
end | ||
fprintf('Found %d frames\n',iFrameAll-1) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
function scores = evaluate_align(groundTruth,deblurred,metric) | ||
% BENCHMARK_EVAL_IMAGE computes various quality measures given | ||
% a deblurred image and the corresponding ID, i.e. you have to | ||
% provide the image and kernel number | ||
% | ||
% Michael Hirsch and Rolf Koehler (c) 2012 | ||
|
||
addpath(genpath('image_quality_algorithms')) | ||
|
||
% ----------------------------------------------------------------- | ||
% Check that input images are 8bit. | ||
% To use the image quality assessment algorithms the images have to be in 8 | ||
% bit, with a maximum value of 255, so not normalized. | ||
% ----------------------------------------------------------------- | ||
if ( ~isa(deblurred, 'uint8') || size(deblurred,3)~=3 ) | ||
error('Input image has to be a color image of type uint8!'); | ||
end | ||
|
||
% z will denote the estimated, i.e. deblurred image | ||
z = double(deblurred); | ||
|
||
% Create constant image which will act as a mask | ||
c = ones(size(deblurred)); | ||
|
||
% Initialize containers for quality measures | ||
mse = []; | ||
mssim = []; | ||
vif = []; | ||
ifc = []; | ||
psnr = []; | ||
mad = []; | ||
|
||
|
||
% ================================================================= | ||
% compute the image quality measure score | ||
% ----------------------------------------------------------------- | ||
|
||
|
||
% Load ground truth image, denoted by x | ||
x = double(groundTruth); | ||
xf = fft2(mean(x,3)); | ||
|
||
% Scale image intensity | ||
zs = (sum(vec(x.*z)) / sum(vec(z.*z))) .* z; | ||
zf = fft2(mean(zs,3)); | ||
|
||
% Estimate shift by registering deblurred to ground truth image | ||
[output Greg] = dftregistration(xf, zf, 1); | ||
shift = output(3:4); | ||
|
||
% Apply shift | ||
cr = imshift(double(c), shift, 'same'); | ||
zr = imshift(double(zs), shift, 'same'); | ||
xr = x.*cr; | ||
|
||
% Compute various quality measures | ||
switch metric | ||
case 'MSE' | ||
mse = [mse metrix_mux(xr, zr, 'MSE')]; | ||
case 'MSSIM' | ||
mssim = [mssim metrix_mux(xr, zr, 'MSSIM')]; | ||
case 'VIF' | ||
vif = [vif metrix_mux(xr, zr, 'VIF')]; | ||
case 'IFC' | ||
ifc = [ifc metrix_mux(xr, zr, 'IFC')]; | ||
case 'PSNR' | ||
psnr = [psnr metrix_mux(xr, zr, 'PSNR')]; | ||
case 'MAD' | ||
MAD_temp = MAD_index(xr, zr); | ||
mad = [mad MAD_temp.MAD]; | ||
end | ||
|
||
|
||
% ================================================================= | ||
% Save results | ||
% ----------------------------------------------------------------- | ||
switch metric | ||
case 'MSE' | ||
scores.MSE = mse; | ||
case 'MSSIM' | ||
scores.MSSIM = mssim; | ||
case 'VIF' | ||
scores.VIF = vif; | ||
case 'IFC' | ||
scores.IFC = ifc; | ||
case 'PSNR' | ||
scores.PSNR = psnr; | ||
case 'MAD' | ||
scores.MAD = mad; | ||
end | ||
|
||
return | ||
|
Oops, something went wrong.