MATLAB Answers


YUV420 to RGB Conversion Conversion

Asked by Imran Kanjoo on 29 Aug 2019
Latest activity Edited by Imran Kanjoo on 30 Aug 2019
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.


Sign in to comment.

0 Answers