当前位置:文档之家› 基于块的全搜索运动估计算法实现实验报告

基于块的全搜索运动估计算法实现实验报告

数字视频处理
实验报告

学 院: 通信与信息工程学院
系 班: 电信科0901班
姓 名:
学 号:
时 间: 2012 年11月23号
一、实验名称:基于块的全搜索运动估计算法实现
二、实验目的:
1、掌握运动估计算法的实现原理。
2、掌握运动估计算法的研究现状及多种计算方法。
3、学习基于块的全搜索运动估计算法,研究分析其Matlab实现
程序过程,并补充完成程序,对实验结果进行分析比较。

三、实验要求
三、实验要求
1、 对实验程序motionEstAnalysis.m进行分析,完成主程序流程图。

函数流程图:
2、编写补充完成部分不全程序代码,调试程序使其能正确运行
(1) motionEstES( )
% Computes motion vectors using exhaustive search method(全搜索法计算
运动矢量)
%
% Input
% imgP : The image for which we want to find motion vectors(当前图
像)
% imgI : The reference image(参考图像)
% mbSize : Size of the macroblock(宏块尺寸)
% p : Search parameter (read literature to find what this means)(搜
索参数)
%
% Ouput
% motionVect : the motion vectors for each integral macroblock in imgP
(当前图像中每一个积分宏块的运动矢量)
% EScomputations: The average number of points searched for a
macroblock(每个宏块搜索的平均点数)
%
% Written by Aroh Barjatya
function [BlockCenter, motionVect, EScomputations] = motionEstES(imgP,
imgI, mbSize, p) % 定义函数文件motionEstES.m,imgP、 imgI、 mbSize、 p
为传入参数,BlockCenter、motionVect、 EScomputations为返回参数

[row col] = size(imgI); % 将参考图像的行数赋值给row,
列数赋值给col

blockcenter = zeros(2,row*col/mbSize^2);
vectors = zeros(2,row*col/mbSize^2); % 定义全0的矢量矩阵的大小
costs = ones(2*p + 1, 2*p +1) * 65537; % 定义最小绝对差矩阵的大小

computations = 0; % 搜索点数赋初值为0
% we start off from the top left of the image(从图像左上角开始)
% we will walk in steps of mbSize(以宏块尺寸为步长)
% for every marcoblock that we look at we will look for
% a close match p pixels on the left, right, top and bottom of it (对
于每一个宏块,在它的上下左右找到与搜索参数p最匹配的像素)

mbCount = 1; %搜索的宏块数赋初值为1
%1为循环起始值,mbSize为步长值,row-mbSize+1为循环终止值
for i = 1 : mbSize : row-mbSize+1
for j = 1 : mbSize : col-mbSize+1
% the exhaustive search starts here(全搜索开始)
% we will evaluate cost for (2p + 1) blocks vertically
% and (2p + 1) blocks horizontaly(我们将计算水平方向上(2p + 1)
个块的最小绝对差和垂直方向上(2p + 1)个块的最小绝对差)
% m is row(vertical) index(m为行指数)
% n is col(horizontal) index(n为列指数)
% this means we are scanning in raster order

for m = -p :
p %水平方向上位移矢
量范围
for n = -p :
p %垂直方向上位移矢量范

% 补充下面程序

% row/Vert co-ordinate for ref block (参考块的行(垂直
方向)的范围)
refBlkVer = i+m;

% col/Horizontal co-ordinate(参考块的列(水平方向)的范
围)
refBlkHor = j+n;

%如果参考块的行列范围的任意一个在已经搜索过的宏块之
外,则继续下一步的搜索
if ( refBlkVer < 1 || refBlkVer+mbSize-1 > row ...
|| refBlkHor < 1 || refBlkHor+mbSize-1 > col)
continue;
end

costs(m+p+1,n+p+1) =
costFuncMAD(imgP(i:i+mbSize-1,j:j+mbSize-1), ...

imgI(refBlkVer:refBlkVer+mbSize-1, refBlkHor:refBlkHor+mbSize-1),
mbSize);

% 搜索下一个点
computations = computations + 1;

end
end

% Now we find the vector where the cost is minimum
% and store it ... this is what will be passed back.(现在找到
有最小绝对差的矢量并存储它,这就是将被返回的东西)

% 补充下面程序
blockcenter(1,mbCount) = i+ mbSize/2-1;

blockcenter(2,mbCount) = j+ mbSize/2-1;

% finds which macroblock in imgI gave us min Cost(找到参考图
像中最小绝对差的宏块)
[dx, dy, min] = minCost(costs);

% row co-ordinate for the vector(矢量的行集合)
vectors(1,mbCount) = dy-p-1;
% col co-ordinate for the vector(矢量的列集合)
vectors(2,mbCount) = dx-p-1;

%搜索下一个宏块
mbCount = mbCount + 1;

costs = ones(2*p + 1, 2*p +1) * 65537;
end
end

BlockCenter = blockcenter;
motionVect = vectors; %返回当前图像中每一个
积分宏块的运动矢量
EScomputations = computations/(mbCount - 1); %返回每个宏块搜索的平
均点数

(2) costFuncMAD( )

% Computes the Mean Absolute Difference (MAD) for the given two blocks(对
给定的两个块计算最小绝对差)
% Input
% currentBlk : The block for which we are finding the MAD(当前块)
% refBlk : the block w.r.t. which the MAD is being computed(参考块)
% n : the side of the two square blocks
%
% Output
% cost : The MAD for the two blocks(两个块的最小绝对差)
%
% Written by Aroh Barjatya
% 定义函数文件costFuncMAD.m,currentBlk、refBlk、 n为传入参数,cost
为返回参数
function cost = costFuncMAD(currentBlk,refBlk, n)
% 补充下面程序
cost=sum(sum(abs(currentBlk-refBlk)))/(n*n);

(3) minCost( )
% Finds the indices of the cell that holds the minimum cost(找到拥有最小绝对
差的点的指数)
%

相关主题