MATLAB Answers


i am taking image as input to the code.But image are not proper.

Asked by jay
on 27 Dec 2013
Latest activity Commented on by ravi
on 20 Feb 2014

This is my code

close all;
clear all;
obj = videoinput('winvideo', 1);
set(obj, 'SelectedSourceName', 'input1');
src_obj = getselectedsource(obj);
frame = getsnapshot(obj);

Its simple image from videoinput.....But i am attaching picture that matlab shows me....Is there any kind of setting need while using this code....Code is correct at has been taking from library file of videoinput() function.I have changed two camera. Check out attachment of image.


Log in to comment.

2 Answers

Answer by Image Analyst
on 27 Dec 2013
 Accepted Answer

Is it color or black and white? What function are you using to display it, imshow(), image(), or imagesc()?


winvideo_1 YUY2_160x120; YUY2_352x288; YUY2_320x240; YUY2_176x144;

Oh bummer. You have one of those cameras that doesn't have an RGB mode. All is not lost though. There is an option of videoinput() that lets you set the returned video mode to convert it into an RGB image. Check out this link by David Tarkowski, the developer of this toolbox at the Mathworks:

vid = videoinput('winvideo', 1);
set(vid, 'ReturnedColorSpace', 'RGB');
img = getsnapshot(vid);

oh man..... really thanks a lot.....:).

Log in to comment.

Answer by Walter Roberson
on 27 Dec 2013

It appears to me that you are getting something that is not in RGB colorspace. Use


to see the available formats. See


Still same kind of image is coming.

imaqfind() does not change the image format, it shows you the available image formats. You then have to pick an appropriate one and add it to the videoinput() call.

use obj.ReturnedColorSpace='rgb'; just after obj = videoinput('winvideo', 1);

Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today