-
Notifications
You must be signed in to change notification settings - Fork 0
/
vidtoim.m
55 lines (40 loc) · 1.5 KB
/
vidtoim.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
clc
clear
% Input video file path
inputVideoPath = '.\input_video.mp4';
% Output video file path
outputVideoPath = 'output_video.mp4';
% Create a VideoReader object
videoObj = VideoReader(inputVideoPath);
% Initialize VideoWriter for output video using H.264 compression
outputVideo = VideoWriter(outputVideoPath, 'MPEG-4');
outputVideo.FrameRate = videoObj.FrameRate;
open(outputVideo);
i=0;
totalSSIM = 0;
% Process frames while reading the input video
while hasFrame(videoObj)
disp(i);
i=i+1;
frame = readFrame(videoObj);
% Process the frame (you can add your processing code here)
[r,t]=Bounding_function(frame,4);
processedFrame = r; % Replace with your processing logic
% Calculate SSIM between original and processed frame
frame = im2double(frame);
processedFrame = im2double(processedFrame);
ssimValue = ssim(frame, processedFrame);
% Accumulate SSIM for average calculation
totalSSIM = totalSSIM + ssimValue;
% Display SSIM for each frame
disp(['SSIM for frame ', num2str(i), ': ', num2str(ssimValue)]);
% Write the processed frame to the output video
writeVideo(outputVideo, processedFrame);
end
% Close the output video
close(outputVideo);
% Calculate and display the average SSIM
averageSSIM = totalSSIM / i;
disp(['Average SSIM: ', num2str(averageSSIM)]);
% Display completion message
fprintf('Video processing complete. Output saved to "%s".\n', outputVideoPath);