Help with block matching (full search) algorithm

6 Ansichten (letzte 30 Tage)
beppo
beppo am 30 Nov. 2017
Bearbeitet: Martin Waciewski am 16 Dez. 2018
Hi, starting from this post, I am trying to implement a block matching full search algorithm. However I have an error (Subscript indices must either be real positive integers or logicals.) that I can't fix. Also I'd need some help to plot the final image with the vectors using the quiver function.
Thank you.
Here's my code
clear;
clc;
blockMatching('DatasetB.avi',200, 16, 20);
% The function parameters are:
% - video_path: video source
% - index: frame number
% - N: block size
% - R: search range
function motionVect = blockMatching(video_path, index, N, R)
VidObj = VideoReader(video_path);
% get 2 consecutive frames
f1 = read(VidObj, index);
f2 = read(VidObj, index+1);
[height, width] = size(f2);
for i = 1:N:height-N
for j = 1:N:width-N
MAD_min = 256*N*N;
mvx = 0;
mvy = 0;
for k = -R:1:R
for l = -R:1:R
MAD = sum(sum(abs(f1(i:i+N-1, j:j+N-1) - f2(i+k:i+k+N-1, j+l:j+l+N-1))));
if (MAD < MAD_min)
MAD_min = MAD;
dy = k;
dx = l;
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);
iblk = floor((i-1)/(N+1));
jblk = floor((j-1)/(N+1));
mvx(iblk, jblk) = dx;
mvy(iblk, jblk) = dy;
end
end
end

Antworten (1)

Martin Waciewski
Martin Waciewski am 16 Dez. 2018
Bearbeitet: Martin Waciewski am 16 Dez. 2018
You should first convert the frames into grayscale by using rgb2gray. And i = 1 - 20 is negative

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by