views:

599

answers:

3

Hello;

I have yuv sequences and I want to convert it to bmp images.And I want to save it to folder on my computer.

I used yuv2bmp m file in http://www.mathworks.com/matlabcentral/fileexchange/25563-convert-420-yuv-to-bmp .

Altough Yuv file is 44MB, unfortunately Matlab gave memory error. How can I overcome of this problem? Could you help me please?

Best Regards..

A: 

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.

Andres
+1  A: 

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.

gnovice
+1  A: 

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.

Jonas