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

20 visualizzazioni (ultimi 30 giorni)
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
MAD_min = 256*N*N
MAD = MAD_min
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
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
else
MAD = MAD_min
dx = dx
dy = dy
end
else
MAD = MAD_min
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);
  3 Commenti

Accedi per commentare.

Risposte (2)

Image Analyst
Image Analyst il 30 Set 2013
Check out the VideoReader() class.

Knut
Knut il 22 Ago 2017
The weights in the top of your code seems to be the Y-weights in standard YCbCr: https://en.wikipedia.org/wiki/YUV
Thus it is probably written to accept "rgb" as input and generate a luma mixture for processing.
I don't know that there is a single standardized YUV video format (it could have subsampled chroma or not, interleaved or planar color components etc). Thus you need to figure out your YUV video format, possibly use fopen/fread/fclose to read each frame into memory, discard the U and V planes and feed the Y plane directly into line#5 of your script.

Community Treasure Hunt

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

Start Hunting!

Translated by