Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to extract Y,U, and V components from a given yuv file using Matlab? Each component is used for further pixels level manipulation
    text
    copied!<p>Hey guys. I'm currently playing with YUV file. Do you have any suggestion on how to extract y,u,v components from a yuv video? I <a href="https://stackoverflow.com/questions/3614441/how-to-extract-frames-from-yuv-420-video-clip-and-store-them-as-different-images/3614567#3614567">found</a> a <a href="http://www.mathworks.com/matlabcentral/fileexchange/6318-convert-yuv-cif-420-video-file-to-image-files" rel="nofollow noreferrer">piece of program</a> which was shown below. But I don't know which part is the valid components that I want. Thanks.</p> <pre><code>% function mov = loadFileYuv(fileName, width, height, idxFrame) function [mov,imgRgb] = loadFileYuv(fileName, width, height, idxFrame) % load RGB movie [0, 255] from YUV 4:2:0 file fileId = fopen(fileName, 'r'); subSampleMat = [1, 1; 1, 1]; nrFrame = length(idxFrame); for f = 1 : 1 : nrFrame % search fileId position sizeFrame = 1.5 * width * height; fseek(fileId, (idxFrame(f) - 1) * sizeFrame, 'bof'); % read Y component buf = fread(fileId, width * height, 'uchar'); imgYuv(:, :, 1) = reshape(buf, width, height).'; % reshape RESHAPE(X,M,N) returns the M-by-N matrix %whose elements are taken columnwise from X. %An error results if X does not have M*N elements % read U component buf = fread(fileId, width / 2 * height / 2, 'uchar'); imgYuv(:, :, 2) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample % read V component buf = fread(fileId, width / 2 * height / 2, 'uchar'); imgYuv(:, :, 3) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample % normalize YUV values % imgYuv = imgYuv / 255; % convert YUV to RGB imgRgb = reshape(convertYuvToRgb(reshape(imgYuv, height * width, 3)), height, width, 3); % imgRgb = ycbcr2rgb(imgYuv); %imwrite(imgRgb,'ActualBackground.bmp','bmp'); mov(f) = im2frame(imgRgb); % mov(f).cdata = uint8(imgRgb); % mov(f).colormap = []; % imwrite(imgRgb,'ActualBackground.bmp','bmp'); %figure, imshow(imgRgb); %name = 'ActualBackground.bmp'; %Image = imread(name, 'bmp'); %figure, imshow(Image); end fclose(fileId); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload