Please help in Shot segmentation with Key Frame selection using Absolute difference
Show older comments
Hello everyone and have a good day.
I would like someone to be able to show me or use a Matlab code to do the following.
1. Segmenting shots of a video, then having a video segmented into several videos.
2. Extract the key-frames.
in point 2, I have a code that downloads from here and works well, but I have a few doubts this is the code (https://de.mathworks.com/matlabcentral/fileexchange/51238-key-frame-extraction-from-video-using-videoreader?focused=3880674&tab=function)
clc;
clear all;
V = 'Batman2.wmv'; % Video Name
xyloObj = VideoReader (V); % Using video reader reading video
% Extracting frames
T = xyloObj.NumberOfFrames% Calculating number of frames
for g = 1: T
p = read (xyloObj, g); % Retrieve data from video
if (g ~ = xyloObj.NumberOfFrames)
J = read (xyloObj, g + 1);
th = difference (p, J); % To calculate histogram difference between two frames
X (g) = th;
end
end
% calculating mean and standard deviation and extracting frames
mean = mean2 (X)
std = std2 (X)
threshold = std + mean * 4
for g = 1: T
p = read (xyloObj, g);
if (g ~ = xyloObj.NumberOfFrames)
J = read (xyloObj, g + 1);
th = difference (p, J);
if (th> mean)% Greater than threshold select as a key frame
filename = fullfile ('E: \ Keyframes', sprintf ('frame_% 05d.JPG', g)); % Writing the keyframes
imwrite (J, filename);
end
end
end
function [r] = difference (f1, f2)
k = rgb2gray (f1); % Convert into gray scale
l = rgb2gray (f2);
f11 = imhist (k); % histogram of data
f12 = imhist (l);
diffe = imabsdiff (f11, f12); % Absolute difference of two images
r = sum (diffe);
end
My first doubt is:
in the condition for comparison with the Treshold:
if (th> mean)% Greater than threshold select as a key frame
should be
if (th> threshold)% Greater than threshold select as a key frame
and my second doubt.
could explain to me, Why in the calculation of threshold = std + mean * 4, the value of Mean is multiplied by 4
Answers (0)
Categories
Find more on Video Formats and Interfaces in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!