视频压缩 运动估计算法 matlab代码

视频压缩 运动估计算法 matlab代码,第1张

这几种运动估计都比较简单,我建议你参考《视频信号处理》这本书

我给你FS的代码你可以参考

function [f_diff_final,MVs]=BlockMatch(fc,fr,N,W,type,bShow)
% [f_diff,MVs]=BlockMatch(fc,fr,N,W,type,bShow)
% Block matching algorithm
% fc is the current frame, fr is the refernce frame
% N is the block size and W is the half size of the searching window
% The actual size of the searching window is 2W+1 X 2W+1
% type: searching strategy ('FS' = default, 'TSS', 'TDL', 'OTS', 'CSA', 'OSA')
% bShow: show the difference image with estimated motion vectors (default: 0)
% type is the searching strategies, currently only "FS" (full search) is
% supported
% The output includes the frame difference with motion compensation,
% f_diff, and the estimated motion vectors of all blocks, MVs (which is a
% 2-D cell matrix)
f_diff_final=[];
f_diff=[];
MVs=[];
if nargin<2
    disp('At least twp arguments are needed!');
    return;
end
if any(size(fc)~=size(fr))
    disp('The two frames should be of the same size!');
    return;
end
if nargin<6
    bShow=0;
    if nargin<5
        type='FS'; % Full search
        if nargin<3
            N=8;
        end
        if nargin<4
            W=N2;
        end
    end
end
N_1=N-1;
f_size=size(fc);
fc=double(fc);
fr=double(fr);
if numel(f_size)~=2
    disp('The input frames must be 2-D matrices!');
    return;
end
if any(rem(f_size,N)~=0)
    disp('The size of the frames should be exactly dividable by the block size!');
    return;
end
height=f_size(1);
width=f_size(2);
f_diff=zeros(f_size);
MVs=cell(height/N,width/N);
for x=1:N:width
    for y=1:N:height
        % Set searching window
        ymin=max(1,y-W);
        ymin_1=ymin-1;
        ymax=min(height-N_1,y+W);
        xmin=max(1,x-W);
        xmin_1=xmin-1;
        xmax=min(width-N_1,x+W);
        fc_block=fc(y:y+N_1,x:x+N_1); % To-be-encoded block
        xxyys_checked=zeros(ymax-ymin_1,xmax-xmin_1); % Flags for checked locations
            % Add new searching strategies here         
             % {'FS','FullSearch','Full Search'}; 
                MSEs=Inf(ymax-ymin_1,xmax-xmin_1);
                block_diff=cell(size(MSEs));
                for xx=xmin:xmax
                    for yy=ymin:ymax
                        block_diff_new=fc_block-fr(yy:yy+N_1,xx:xx+N_1);
                        block_diff{yy-ymin_1,xx-xmin_1}=block_diff_new;
                        MSEs(yy-ymin_1,xx-xmin_1)=mean(abs(block_diff_new(:)));
                    end
                end
                % Get the minimal MSE and the 1-D index
                [MSE_min,index]=min(MSEs(:));
                % Transform the 1-D index into 2-D index
                [yy_min,xx_min]=ind2sub(size(MSEs),index);
                % Set the motion vector
                MVs{ceil(y/N),ceil(x/N)}=[ymin+yy_min-y xmin+xx_min-x];
                % Set the difference block with motion compensation
                f_diff(y:y+N_1,x:x+N_1)=block_diff{yy_min,xx_min};
    end
end
f_diff_final=int16(f_diff);

以上就是关于视频压缩 运动估计算法 matlab代码全部的内容,包括:视频压缩 运动估计算法 matlab代码、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10112372.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存