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.


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()?


on 31 Dec 2013

winvideo_1 YUY2_160x120; YUY2_352x288; YUY2_320x240; YUY2_176x144;

Image Analyst
on 31 Dec 2013

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);
on 31 Dec 2013

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

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


on 28 Dec 2013

Still same kind of image is coming.

Walter Roberson
on 28 Dec 2013

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.

on 20 Feb 2014

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

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!