YUV420 to RGB Conversion Conversion
65 views (last 30 days)
I am using this code to read YUV420 and convert to RGB. Because I have YUV420.YUV image file but that code is for video therefore, I only read 1frame. Then I get YUV as Y as the full size but U and V as half size as described at wikiepdia. I then resze the images to the full size of the image and apply YUV to RGB coversion. But the RGB images are not in correct colours. I have attached the files so that you can run and see what is the problem. Here is the YUV filetulips_yuv420_inter_planar_qcif.yuv
I have two more questions;
Firstly, The size of the "stream" for one frame should be equal to 1.5*the size of the Y but it is very large whether I use uint8 or uint16 to read the file.
Secondly, If I have 10bit YUV420 file how to I to modify this code to show correct RGB.
fname = 'tulips_yuv420_inter_planar_qcif.yuv';
width = 176;
height = 144;
fid = fopen(fname,'r'); % Open the video file
% stream = fread(fid,'uint16'); % uint16
stream = fread(fid); % uint8
length = 1.5 * width * height; % Length of a single frame
The full code is attached kindly help to sort out the issue.
Pratheek Punchathody on 7 Apr 2021
As per my understanding in case of YUV Color model, Y stands for the luminance component and U and V are the chrominance component. YUV is used for the specific analog encoding of color information and YCbCr is used for digital encoding of color information suited for video and still image compression and transmission.
In MATLAB, function called "ycbcr2rgb" which converts YCbCr color values to RGB color space. It allows to accept single | double | uint8 | uint16 data types of inputs. Converted RGB color values, returned as a numeric array of the same size as the input. The output data type is the same as the input data type.