How to compare frames of a video in MATLAB by histogram level?
Afficher commentaires plus anciens
I have written code that stores a video as an array of frames, however now I want to compare the individual frames via their histogram levels and return a message when a significant difference is detected between frames, how would I go about doing this?
Réponses (1)
Image Analyst
le 29 Avr 2017
Sudden changes in the histogram can indicate things in a video, like abrupt scene changes. However you may not need to get the whole histogram, you might be able to just use mean2 on the whole frame
grayImage = rgb2gray(thisFrame);
meanGrayLevel = mean2(grayImage);
However mean gray level, and even the complete histogram is not a measure of how alike the images are. For example, take any image. Now cut the intensity in half. It still "looks" a lot like the original image, even though its histogram is drastically shifted. Now take the original image and sort the gray levels so that the image looks like a ramp. That image would look nothing like the original image even though their histograms are 100% identical (because the same pixels are there, they're just moved around to new locations).
It might help if you said what you were really after so we could help with the proper algorithm.
9 commentaires
Rita Lisenkova
le 29 Avr 2017
Image Analyst
le 29 Avr 2017
16.7.2.6.1 Driver Monitoring, Eyes, Gaze
for papers showing how they do it.
Rita Lisenkova
le 30 Avr 2017
Image Analyst
le 30 Avr 2017
They're relevant to the extend that you can take the algorithm and code it up in MATLAB. This is because it's such a niche application that there is nothing built into MATLAB for doing exactly that so you must write your own. So which paper did you code up, and do you need help with your code?
Rita Lisenkova
le 30 Avr 2017
Image Analyst
le 30 Avr 2017
You call getsnapshot() to pull a frame from teh live video. Then after you do that you call your functions. getsnapshot will be in a loop for as long as you want to run it. For pre-recorded video it will most likely be a loop for every frame in the video. For a live video you will loop until something happens, like a predetermined amount of time has elapsed or the user clicks something on the GUI or however you want to stop it.
Rita Lisenkova
le 30 Avr 2017
Image Analyst
le 30 Avr 2017
No need to create an image stack with B as far as I can tell, simply do this
while hasFrame(vid)
thisFrame = readFrame(vid); % Get one RGB frame of the color video.
redChannel = thisFrame(:,:,1); % Extract red channel only.
[pixelCounts, grayLevels] = imhist(redChannel); % Get histogram of red channel.
% Now do something with pixelCounts, grayLevels, and redChannel....
end
Rita Lisenkova
le 30 Avr 2017
Catégories
En savoir plus sur Image Processing and Computer Vision 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!