## How to read a yuv (or avi file) into matlab for video processing

### Chaine San Buenaventura (view profile)

on 30 Sep 2013
Latest activity Commented on by Walter Roberson

### Walter Roberson (view profile)

on 23 Aug 2017
What code should i insert above the code below which reads a yuv file (but if not possible, an avi file) for the following video processing. The code below is an algorithm that performs motion compensation. What are the output of this code?
% convert images to grayscale
%f1 = 0.2989*f1(:,:,1) + 0.5870*f1(:,:,2) + 0.1140*f1(:,:,3);
%f2 = 0.2989*f2(:,:,1) + 0.5870*f2(:,:,2) + 0.1140*f2(:,:,3);
[height width] = size(f1); %size of first frame
N = 16; % blocksize
mvx=[]; mvy=[]; ii = 1; fp = uint8(zeros(height,width));
for i = 1:N:height
jj = 1;
for j = 1:N:width %for every block in the anchor frame
dx = 0
dy = 0
for k = -R:1:R % defines search range
for l = -R:1:R %defines search range, for every search candidate
if ~(i+k<=0 | j+l<=0 | i+k+N-1>height | j+l+N-1>width) % if inside boundary
dy = k
dx = l
else
dx = dx
dy = dy
end
else
dx = dx
dy = dy
end
% calculate MAD for this candidate
end
end
%put the best matching block in the predicted image
fp(i:i+N-1,j:j+N-1) = f2(i+dy:i+dy+N-1,j+dx:j+dx+N-1);
mvx(ii,jj) = dx;
mvy(ii,jj) = dy; %record the estimated MV
jj = jj + 1
end
ii = ii + 1
end
figure; imshow(f1); title('anchor image');
figure; imshow(f2); title('target image');
figure; imshow(fp); title('predicted image');
figure; imshow(f1-fp); title('prediction image error');
figure; quiver(mvx,mvy); axis ij;
f11 = double(f1); fpp = double(fp);
err = 0;
for c1 = 1:height
for c2 = 1:width
err = err + (f11(c1,c2) - fpp(c1,c2))^2;
end
end
mse = err/(height*width);
psnr = 10*log10((pk^2)/mse);
pk = 255; %double(max(max(f1)));
fprintf('PSNR = %f dB\n',psnr);

Thien Thu Ngo

### Thien Thu Ngo (view profile)

on 22 Aug 2017
What is R in this code?
Walter Roberson

### Walter Roberson (view profile)

on 22 Aug 2017
R is a value passed in by the user, to the function version of this code, such as is shown at https://www.mathworks.com/matlabcentral/answers/29853-getting-an-error-subscript-indices-must-either-be-real-positive-integers-or-logicals
Walter Roberson

on 23 Aug 2017

on 30 Sep 2013