Remove static background from video

18 次查看(过去 30 天)
I have a video, attached to this question, whose background needs to be extracted. The background is composed of the static elements that are reflections from the glass surface. Ideally, only the mouse and the attached cables should be left after subtracting the background. I have tried global threshold but have not had much success with it and would appreciate any help!

回答(1 个)

Image Analyst
Image Analyst 2023-5-17
编辑:Image Analyst 2023-5-17
I don't think it's too hard. First you have to process some frames where the mouse is moving and get a "mode" image, which is the pixel value that the pixel has most of the time (so you can't process frames where the mouse is in one position the majority of the time or the mode value will be the mouse and not the background). Or you can simply snap a photo before the mouse is introduced to the scene.
Once you have a mode/background image, then you can simply use imabsdiff to find out what pixels are different from the background and set those to zero.
mask = imabsdiff(thisFrame, backgroundImage) > 10;
% Get rid of small blobs smaller than 10 pixels.
mask = bwareaopen(mask, 10);
% Mask image by multiplying each channel by the mask.
maskedFrame = thisFrame .* cast(mask, 'like', thisFrame); % R2016b or later. Works for gray scale as well as RGB Color images.
Of course it would be better to avoid the problem in the first place. Use better, brighter lights. Put a polarizing sheet in front of the outside lamps and a rotating polarizer on the camera lens. Rotate the polarizer on the lens to minimize the reflections.

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by