MATLAB Answers

0

Comparing consecutive png files (video frames)

Asked by amonasro on 15 Jan 2018
Hi,
I have extracted png files from a video for each frame. I have the png files in a folder and I can read all the files in a loop.
To be able to detect scene cuts in the video, I need to perform some kind of comparison between consecutive frames. I want to use 2 methods.
1. Compare the pixels values and check if the euclidean distance between consecutive frames is greater than a treshold value. (rgb values will be the 3 dimensions of the vectors to find the distance) How can I reach the RGB values of each pixel and find the distance to the same pixel in the consecutive png file with a reasonable efficiency?
2. As a second comparison method, I am thinking of comparing the histograms of the consecutive frame png files. I would also need an efficient method to compare the consecutive vectors. Is it ok to rely on a "for loop" or do I need built in Matlab constructs/methods for this purpose?
Thanks in advance

  0 Comments

Sign in to comment.

1 Answer


Hello,
Assuming the camera is not moving, then you can use "imread" to read the video frames, which will give you a NxMx3 matrix, with NxM being the resolution of the image and the third dimension corresponds to RGB values. Then, if you want the RGB values of a specific pixel, you could do
my_image(1,2,:)
for pixel (1,2) and so on. This will give you a comma separated list but you can use "permute" to turn that into a vector:
permute(my_image(1,2,:),[3 2 1])
Then you can use, for example, "norm" to calculate the Euclidean distance between two pixels.
To create histograms, you can use "imhist" and follow the code provided in the link below:
https://www.mathworks.com/matlabcentral/answers/181624-how-to-get-color-histogram-of-an-image
You could use a for loop, but "norm" and "vecnorm" can be applied to matrices as well for speed.

  0 Comments

Sign in to comment.