To find average of the frames extracted from a video
Afficher commentaires plus anciens
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.
Réponses (1)
Naga
le 24 Sep 2024
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');
Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!