How can I find the elapsed time between two images from video file with matlab? I drop a drop of water on a surface. I want to find the water absorption time of the surface from the video I recorded with MATLAB. Can you help me? I don't know much about Matlab.
Kshitij Singh answered .
2025-11-20
video = VideoReader('your_video_file.mp4');
2. Extract two frames from the video.
frame1 = read(video, frame_number_1); frame2 = read(video, frame_number_2);
3. Convert the frames to grayscale.
gray1 = rgb2gray(frame1); gray2 = rgb2gray(frame2);
4. Calculate the absolute difference between the two grayscale frames.
diff = abs(double(gray1) - double(gray2));
5. Threshold the difference image to focus only on the region where the water has been absorbed.
threshold = 50; % adjust as necessary diff_threshold = diff > threshold;
7. Calculate the number of pixels in the thresholded difference image that are white.
num_white_pixels = sum(diff_threshold(:));
8. Calculate the percentage of white pixels.
percentage_white_pixels = num_white_pixels / num_pixels * 100;
9. Calculate the time interval between the two frames using the timestamps of the frames:
time1 = video.Timestamps(frame_number_1); time2 = video.Timestamps(frame_number_2); time_interval = time2 - time1; disp(time_interval);
10.Repeat steps 2-9 for each pair of frames that you want to analyze, and use the percentage of white pixels to estimate the water absorption time of the surface.
Note that this method assumes that the water absorption process appears as a significant increase in brightness in the region in which it occurs. If the water absorption process appears differently in your video, you may need to use a different method to analyze it. Note that you must give all your paths(video) correctly and this should work. Thanks!