% Approximate Median Filter background model for moving object segmentation.
%采用近似中值滤波背景模型参考图像实现运动目标分割
clear all; close all;
% Construct a videoreader class to read a avi file, first the 'car_parking.avi' ,
% then the ‘highwayII_raw.avi'.
videoObj = VideoReader('ddd.mp4');
numFrames =videoObj.NumberOfFrames;
%Get the speed of the AVI movie in frames per second (fps)
FPS = videoObj.FrameRate;
% Read the first frame in the video sequence as the initial value
newframe = read(videoObj, 10);
fmed = double(newframe);
% Get the height, width, and number of color components of the frame
[height, width, numColor] = size(newframe);
% Assign a value to the threshold
Threh = 60;
beta = 0.6;
fg = false(height, width);
%创建方形结构元素,用于对分割结果形态学滤波
se = strel('square',3);
% To avoid consuming too much memories, read only a one frame each time.
for n = 1:numFrames
newframe = read(videoObj, n);
% Calculate the differrence image between the new frame and fmed
Idiff = double(newframe) - fmed;
% Update the median of each pixel value
pixInc = find(Idiff > 0);
fmed(pixInc) = fmed(pixInc) + beta;
pixDec = find(Idiff < 0);
fmed(pixDec) = fmed(pixDec) - beta;
% Motion segment, detection moving object by threholding Idiff
fg = abs(Idiff) >Threh;
if ( numColor == 3) % color image
fg = fg(:, :, 1) | fg(:, :, 2) | fg(:, :, 3);
end
%对分割结果进行形态学滤波
fg2 = imopen(fg,se);
fg2 = imclose(fg2,se);
figure(1);
subplot(1,3,1), imshow(newframe);
title(strcat('Current Image, No. ', int2str(n)));
subplot(1,3,2), imshow(fg);
title('Segmented result using Approximate Median Filter');
subplot(1,3,3), imshow(fg2);
title('Segmented result using morphological filter');
end
%------------------------------------------------------------------
毕业设计方案专家
- 粉丝: 5553
- 资源: 1890
最新资源
- 自考数据库系统原理04735真题含答案(2011.1-2017年)
- YOLO算法-有轨车辆数据集-2013张图像带标签-身体-联轴器-车轮.zip
- YOLO算法-火车-轨道数据集-2164张图像带标签-火车-轨道.zip
- 05-大数据概论(1).zip
- WebSocketB/S前后端链接通信-simple-Chat实现(应用)
- YOLO算法-瓶纸盒合并数据集-3161张图像带标签-纸张-纸箱-瓶子.zip
- YOLO算法-检测车数据集-2622张图像带标签-货车-发动机.zip
- YOLO算法-自卸卡车-挖掘机-轮式装载机数据集-2644张图像带标签-自卸卡车-挖掘机-轮式装载机.zip
- 离散数学课件全国自考02324
- YOLO算法-火灾和人员探测数据集-3039张图像带标签-人-烟-火.zip
- YOLO算法-产品识别数据集-5166张图像带标签-可口可乐.zip
- YOLO算法-数据集数据集-330张图像带标签-椅子-书桌.zip
- SwinTransformer 改进:添加SelfAttention自注意力层
- YOLO算法-可回收垃圾检测数据集-1142张图像带标签-纸张-纸箱-瓶子.zip
- YOLO算法-锡罐-牙罐-盖子打开数据集-179张图像带标签-锡罐-牙罐-盖子打开.zip
- YOLO算法-汽车数据集-5000张图像带标签-.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页