问题
I have yuv sequences and I want to convert them to bmp images. I want to save it to a folder on my computer.
I used the yuv2bmp m file in this link .
Although the Yuv file is only 44MB, Matlab threw a memory error. How can I overcome this problem? Could you help me please?
Best Regards...
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
You can use ffmpeg to simply convert between YUV and BMP.
- Download ffmpeg
- Go to command propmt
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.
来源:https://stackoverflow.com/questions/1945374/convert-yuv-sequence-to-bmp-images