使用Matlab删除图像背景

时间:2017-02-10 16:34:02

标签: matlab image-processing background-subtraction

当网络摄像头拍摄图像时,我将进行背景减法。接下来,我将使用已经减去背景的图像来查找红色和绿色均值。但是有一个错误。该错误表示索引超出了矩阵维度'和绿色错误= I(:,:,2); 。它只显示红色均值。有人可以帮帮我吗。谢谢。

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);

0 个答案:

没有答案