% Function : Integer Pixel EBMA
% Author ��Zexun Wang @ HIT - P.R.China
% E-mail : wangzexun@gmail.com
% Date : 17th,Feb.,2009
% f1 : anchor frame
% f2 : target frame
% fp : predicted image
% mvx , mvy : store the MV image
% width * height : image size
% N : block size
% R : search range
clc;
clear all;
close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Import Relative Data %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f1 = fopen('foreman100.Y');
f2 = fopen('foreman109.Y');
f1 = fread(f1,[352,288]);
f2 = fread(f2,[352,288]);
f1 = double(f1)';
f2 = double(f2)';
[height,width] = size(f1);
N = 16;
R = input('\nPlease indicate the search range R\n');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% EBMA Main Function %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mvx = zeros(height/N,width/N);
mvy = zeros(height/N,width/N);
for i = 1 : N : height - N + 1 % for every block in the anchor frame : height
for j = 1 : N : width - N + 1 % for every block in the anchor frame : width
MAD_min = 256 * N * N;
for k = -R : 1 : R
for kk = -R : 1 : R % for every search candidate
if (i+k>0)&&(j+kk>0)&&(i+k+N-1<height+1)&&(j+kk+N-1<width+1)
% evaluate before MAD calculation
MAD = sum(sum(abs(f1(i:i+N-1,j:j+N-1)-f2(i+k:i+k+N-1,j+kk:j+kk+N-1))));
% calculate MAD for this candidate
if MAD < MAD_min
MAD_min = MAD;
dx = kk;
dy = k;
end
end
end
end
fp(i:i+N-1,j:j+N-1) = f2(i+dy:i+dy+N-1,j+dx:j+dx+N-1);
% put the best matching block in the predicted image
iblk = floor((i-1)/N)+1; % block index
jblk = floor((j-1)/N)+1; % block index
mvx(iblk,jblk) = dx; % record the estimated MV
mvy(iblk,jblk) = dy; % record the estimated MV
end
end
%%%%%%%%%%%%%%%%
%%% Figure %%%
%%%%%%%%%%%%%%%%
subplot(2,2,1);quiver(mvx,mvy);title('Move Vector - Integer Pixel EBMA');
subplot(2,2,2);imshow(fp,[]);title('Predicted Image - Integer Pixel EBMA')
subplot(2,2,3);imshow(f1,[]);title('Anchor Frame - Integer Pixel EBMA');
subplot(2,2,4);imshow(f2,[]);title('Farget Frame - Integer Pixel EBMA')
figure;imshow(f2-fp,[]);title('Error - Integer Pixel EBMA')
%%%%%%%%%%%%%
%%% PSNR %%%
%%%%%%%%%%%%%
f_mse = sum(sum((f2-fp).^2))/(height*width);
f_snr = (352*240)/f_mse;
f_psnr = 10*log(f_snr);
fprintf('\nPSNR(Integer Pixel EBMA) is %f.\n',f_psnr);
评论1
最新资源