When the webcam captured an image I will to do the background subtraction. Next I will use the image that the background is already subtracted to find the red and green mean. But there is an error. The error says 'Index exceeds matrix dimensions' and error in green = I(:,:,2); . It only shows the red mean. Can someone please help me. Thank you.
vid = videoinput('winvideo', 1, 'MJPG_1280x720');
vid.FramesPerTrigger = 1;
vid.ReturnedColorspace = 'rgb';
triggerconfig(vid, 'manual');
vidRes = get(vid, 'VideoResolution');
imWidth = vidRes(1);
imHeight = vidRes(2);
nBands = get(vid, 'NumberOfBands');
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axes2);
preview(vid, hImage);
start(vid);
pause(6);
trigger(vid);
pic = getsnapshot(vid);
stoppreview(vid);
pause(2);
image_resize = imresize(pic, [2448 2448]);
I = im2bw(image_resize,graythresh(image_resize));
axes(handles.axes2);
imshow(image_resize);
%Redmean
red = I(:,:,1);
RedMean = mean(mean(red));
set(handles.edit1,'string',RedMean);
%Greenmean
green = I(:,:,2);
GreenMean = mean(mean(green));
set(handles.edit2,'string',GreenMean);