Convert yuv sequence to bmp images

左心房为你撑大大i 提交于 2019-12-06 06:23:51

As this question doesn't have a fast answer I put here some links that may be helpful to you. But all of then refers more to implementation in C, not Matlab.

Converting Between YUV and RGB

Some sample code in C

That one in Delphi is pretty good. This web site indeed is very nice web site for those that like work with image processing

And a nice article here

Hope it can help you.

Lines 20 to 39 in yuv2bmp.m read

    [Y,U,V]=yuvread(filename,start_frame,num_frame);%4:2:0%%%%%%%%%%%%%%%%

[My Ny iL]=size(Y);
[Mu Nu iu]=size(U);
[Mv Nv iv]=size(V);


for f=1:num_frame
   UU(:,:,f)= imresize(U(:,:,f),[My Ny],'nearest');
   VV(:,:,f)= imresize(V(:,:,f),[My Ny],'nearest');


    image(:,:,1) = Y(:,:,f)+1.402*(VV(:,:,f)-128);
    image(:,:,2) = Y(:,:,f)-0.34414*(UU(:,:,f)-128)-0.71414*(VV(:,:,f)-128);
    image(:,:,3) = Y(:,:,f)+1.772*(UU(:,:,f)-128);

    fname=sprintf('%s%d%s',filename(1:length(filename)-4),f,'.bmp');

    imwrite(uint8(image),fname,'bmp');
end

This looks like it's wasting quite a bit of memory. Unfortunately, I do not have any example yuv images, but try to modify this part of the code the following way, and check whether it still gives you the correct results:

for f=1:num_frame

    % read each image of the sequence separately
    [Y,U,V]=yuvread(filename,start_frame+f-1,1);%4:2:0%%%%%%%%%%%%%%%%

    % in the following three lines, I have replaced UU with U and VV with V, and I've
    % removed all the (:,:,f)
    image(:,:,1) = Y+1.402*(V-128);
    image(:,:,2) = Y-0.34414*(U-128)-0.71414*(V-128);
    image(:,:,3) = Y+1.772*(U-128);

    fname=sprintf('%s%d%s',filename(1:length(filename)-4),f,'.bmp');

    imwrite(uint8(image),fname,'bmp');
end

Also, in lines 52 to 54 of yuvread.m, you can replace 'double' with 'single'. This shaves another 50% off your memory usage, and it should not make any difference to the output, since you are re-casting as uint8 in the end, anyway.

I've never worked with a YUV format, but Wikipedia says:

Today, the term YUV is commonly used in the computer industry to describe file-formats that are encoded using YCbCr.

If you actually are using a YCbCr format, and you have access to the Image Processing Toolbox, you can use the function YCBCR2RGB to convert YCbCr color values to RGB color space, then save the resulting RGB image as a bitmap using IMWRITE.

You can use ffmpeg to simply convert between YUV and BMP.

  1. Download ffmpeg
  2. Go to command propmt
  3. Execute a command like this:

    ffmpeg.exe -s 1280x720 -i input.yuv output.bmp

    ffmpeg.exe -s 1280x720 -i input.bmp output.yuv

don't forget to change the size in the command.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!