Question

I am currently working for a matlab meets my webcam project. Here is my code:

vid = videoinput('winvideo');
vidRes = get(vid, 'VideoResolution');
nBands = get(vid, 'NumberOfBands');
hImage = image( zeros(vidRes(2), vidRes(1), nBands));
preview(vid, hImage);
colormap cool;

The video was displayed as it is in webcam. However the colormap cool; seems no effect in the video. I tried replacing the video by a dummy imag and the colormap cool; takes effect.

Is there any way for me to control the colormap of my video?

Was it helpful?

Solution

Color images (including video frames) are defined using 3 channels, R G B. Colormaps are used when you only have 1 channel of information and MAP a single value to a 3 channel RGB value.

For example:

img1 = rand(20,20,3);
imagesc(img); 
colormap hot; % This does nothing because the image has 3 channels

img2 = rand(20,20);
imagesc(img);
colormap hot; % This works because a colormap is being used to map the 1 channel to a color

If you want to use a colormap for your video you'll have to select either the R, G, or B channel or create a single channel as a combination of multiple channels.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top