Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to convert yuy2 to rgb?

877 views
Skip to first unread message

deepak

unread,
Oct 19, 2009, 2:18:03 AM10/19/09
to
hello everyone... i've been using a webcam to get the frames from my video.. unfortunately the adaptor takes only the yuy2 format only... but the cam can support rgb too... i'm in need of a function that converts yuy2 to rgb images... kindly post your replies... also, i'm in need of the information about YUY2 format...
thanks in advance...

Gabi Teodoru

unread,
Jan 2, 2010, 10:34:02 AM1/2/10
to
"deepak " <deep...@gmail.com> wrote in message <hbh0ar$rs4$1...@fred.mathworks.com>...

> hello everyone... i've been using a webcam to get the frames from my video.. unfortunately the adaptor takes only the yuy2 format only... but the cam can support rgb too... i'm in need of a function that converts yuy2 to rgb images... kindly post your replies... also, i'm in need of the information about YUY2 format...
> thanks in advance...

Hi,

I just submitted my YUY2 to RGB converter to file exchange. But until it appears there, here's the code:

function newdata = YUY2toRGB(data)
%% input is (:,:,1:3), where
%% (:,:,1) is Y, (:,:,2) is U, (:,:,3) is V


Y = single(data(:,:,1));
U = single(data(:,:,2));
V = single(data(:,:,3));

C = Y-16;
D = U - 128;
E = V - 128;

R = uint8((298*C+409*E+128)/256);
G = uint8((298*C-100*D-208*E+128)/256);
B = uint8((298*C+516*D+128)/256);

newdata = uint8(zeros(size(data)));
newdata(:,:,1)=R;
newdata(:,:,2)=G;
newdata(:,:,3)=B;

deepak

unread,
Jan 2, 2010, 11:01:04 AM1/2/10
to
"Gabi Teodoru" <gabit...@gmail.com> wrote in message <hhnp1a$222$1...@fred.mathworks.com>...


thanks for your reply... i'll try it...

Lautaro Carmona

unread,
Feb 12, 2010, 12:37:04 AM2/12/10
to
"deepak " <deep...@gmail.com> wrote in message <hbh0ar$rs4$1...@fred.mathworks.com>...
> hello everyone... i've been using a webcam to get the frames from my video.. unfortunately the adaptor takes only the yuy2 format only... but the cam can support rgb too... i'm in need of a function that converts yuy2 to rgb images... kindly post your replies... also, i'm in need of the information about YUY2 format...
> thanks in advance...

I recently had the same problem, my webcam takes only the YUY2 format...
I solved this problem doing this:

%1st you set the camera to use.
%'camera' is the DeviceID of your camera.

vinfo = imaqhwinfo('winvideo',camera);


%Then you set the video object 'vid', where 'camera' is the DeviceID of your camera.
%'format' is the index which specifies one of the YUY2 formats of your camera.

vid = videoinput('winvideo',camera,vinfo.SupportedFormats{format});

%Finally, you set the ReturnedColorSpace as RGB!

set(vid,'ReturnedColorSpace','rgb'); %<----- This is the command!!!!

Hope It Works!!!!!


Lautaro Carmona

Gabi Teodoru

unread,
Feb 12, 2010, 1:57:02 AM2/12/10
to
Hi,

I referenced your message on my yuy2 to rgb converter M-file page (http://www.mathworks.com/matlabcentral/fileexchange/26249-yuy2-to-rgb-converter).

"Lautaro Carmona" <lcar...@alu.itba.edu.ar> wrote in message <hl2pe0$2jq$1...@fred.mathworks.com>...

kanchan kesari

unread,
Sep 6, 2010, 11:10:11 AM9/6/10
to
"Gabi Teodoru" <gabit...@gmail.com> wrote in message <hl2u3u$132$1...@fred.mathworks.com>...

kanchan kesari

unread,
Sep 6, 2010, 11:16:04 AM9/6/10
to
"Gabi Teodoru" <gabit...@gmail.com> wrote in message <hl2u3u$132$1...@fred.mathworks.com>...
> Hi,
>
> I referenced your message on my yuy2 to rgb converter M-file page (http://www.mathworks.com/matlabcentral/fileexchange/26249-yuy2-to-rgb-converter).
>
> "Lautaro Carmona" <lcar...@alu.itba.edu.ar> wrote in message <hl2pe0$2jq$1...@fred.mathworks.com>...
> > "deepak " <deep...@gmail.com> wrote in message <hbh0ar$rs4$1...@fred.mathworks.com>...
> > > hello everyone... i've been using a webcam to get the frames from my video.. unfortunately the adaptor takes only the yuy2 format only... but the cam can support rgb too... i'm in need of a function that converts yuy2 to rgb images... kindly post your replies... also, i'm in need of the information about YUY2 format...
> > > thanks in advance...
> >
> > I recently had the same problem, my webcam takes only the YUY2 format...
> > I solved this problem doing this:
vinfo=videoinput('winvideo',1);
vid=videoinput('winvideo',1,vinfo.SupportedFormats{'160x120'});
> >but I am getting error as;
Cell contents reference from a non-cell array object.
Can anyone help me why I am getting this error?
Thanks in advance.

Anupam Agarwal

unread,
May 19, 2014, 9:01:12 AM5/19/14
to
"kanchan kesari" <kesari...@gmail.com> wrote in message <i630jk$kf9$1...@fred.mathworks.com>...
This is working very much fine.....
0 new messages