To find average of the frames extracted from a video

4 次查看(过去 30 天)
I wrote a code for extracting image frames from a video.But i am unable to get average of these extracted frames.can anyone please help me? my code is
clc;
close all;
clear all;
mov=aviread('viptraffic_original.avi');
info=aviinfo('viptraffic_original.avi');
k=info.NumFrames;
for i=1:k
m=aviread('viptraffic_original.avi',i);
f=frame2im(m);
figure,imshow(f);
end.

回答(1 个)

Naga
Naga 2024-9-24
Hello Srikanth,
To calculate the average frame, you need to convert each frame to a numerical array, sum them up, and then divide by the total number of frames. Here's how you can modify your code to compute the average frame:
video = VideoReader('viptraffic_original.avi');
% Initialize a matrix to store the sum of all frames
sumFrames = zeros(video.Height, video.Width, 3, 'double');
% Loop through each frame to compute the sum
while hasFrame(video)
frame = im2double(readFrame(video));
sumFrames = sumFrames + frame;
end
% Compute the average frame
averageFrame = sumFrames / video.NumFrames;
% Display the average frame
imshow(averageFrame);
title('Average Frame');

Community Treasure Hunt

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

Start Hunting!

Translated by