User`s guide

Working with Image Data in MATLAB Workspace
7-21
grayscale
3
Create a one-frame image img using the getsnapshot function.
img = getsnapshot(vid);
4
View the size of the acquired image.
size(img)
ans =
480 640
5
The value of the ReturnedColorSpace property is grayscale because Bayer data
is single-banded and the toolbox doesn't yet know that it needs to decode the data.
Setting the ReturnedColorSpace property to 'bayer' indicates that the toolbox
should decode the data.
% Set the color space to Bayer.
vid.ReturnedColorSpace = 'bayer';
6
In order to properly decode the data, the toolbox also needs to know the alignment
of the Bayer filter array. This should be in the camera documentation. You can then
use the BayerSensorAlignment property to set the alignment.
% Set the alignment.
vid.BayerSensorAlignment = 'grbg';
The getdata and getsnapshot functions will now return color data.
% Acquire another image frame.
img = getsnapshot(vid);
% Now check the size of the new frame acquired returning color data.
size(img)
ans =
480 640 3
Remove the image acquisition object from memory.
delete(vid)
clear vid