gpt4 book ai didi

matlab - 如何在Matlab中提取前景图像

转载 作者:太空宇宙 更新时间:2023-11-03 19:53:21 25 4
gpt4 key购买 nike

我有一个 .avi 文件(取自 Actions as Space-Time Shapes - Classification Dataset ),我从中提取了 .png 格式的帧。现在,我想使用 Matlab 从这些图像中进行前景检测。

我见过一个使用 vision.ForegroundDetector() 的代码,但它适用于视频文件。

所以如果有人能给我图像前景检测的代码,那么我将非常感激。

这是一个框架的例子:

enter image description here

最佳答案

由于此视频是用稳定的相机拍摄的,因此您可以轻松地进行背景减法:

%// read the video:
reader = VideoReader('daria_walk.avi');
vid = {};
while hasFrame(reader)
vid{end+1} = im2single(readFrame(reader));
end
%// simple background estimation using mean:
bg = mean( cat(4, vid{:}), 4 );
%// estimate foreground as deviation from estimated background:
fIdx = 43; %// do it for frame 43
fg = sum( abs( vid{fIdx} - bg ), 3 ) > 0.25;

现在你可以看到结果了:

figure;
subplot(131); imshow( bg );
subplot(132); imshow( vid{fIdx} );
subplot(133); imshow( fg );

结果是 enter image description here

关于matlab - 如何在Matlab中提取前景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33931290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com