Find brightest frame in video file
5 views (last 30 days)
Show older comments
I need to import a video file (which contains 1000s or 10,000s of frames) and find the brightest frame; and isolate and save that frame.
The image can br happily converted to greyscale if that makes things easier.
0 Comments
Accepted Answer
Image Analyst
on 9 Jan 2024
See my attached demo that runs through a video getting the mean R, G, and B, and gray scale brightness. Once you've run though the video you can look at the vector of brightnesses to determine which frame was the brightest and then copy that particular frame somewhere, like to disk with imwrite.
8 Comments
Image Analyst
on 12 Jan 2024
Try this:
hFig = figure;
hFig.Name = 'Brightest Frame';
hFig.WindowState = 'maximized';
% Show brightest frame in the middle.
subplot(1, 3, 2);
thisFrame = read(videoObject, max_brightness_image_frame);
% IMPORTANT NOTE: convert to gray level if needed - if that's how you decided upong the brightest frame..
meanOfThisFrame = mean(thisFrame);
imshow(thisFrame);
impixelinfo; % Let user mouse around and see (x, y, RGB)
axis('on', 'image');
caption = sprintf('The brightest frame is #%d and the mean is %.3f', max_brightness_image_frame, meanOfThisFrame);
title(caption);
% Show frame before the brightest frame on the left.
subplot(1, 3, 1);
thisFrame = read(videoObject, max_brightness_image_frame - 1);
% IMPORTANT NOTE: convert to gray level if needed - if that's how you decided upong the brightest frame..
meanOfThisFrame = mean(thisFrame);
imshow(thisFrame);
impixelinfo; % Let user mouse around and see (x, y, RGB)
axis('on', 'image');
caption = sprintf('The frame before is #%d and the mean is %.3f', max_brightness_image_frame - 1, meanOfThisFrame);
title(caption);
% Show frame after the brightest frame on the right.
subplot(1, 3, 3);
thisFrame = read(videoObject, max_brightness_image_frame + 1);
% IMPORTANT NOTE: convert to gray level if needed - if that's how you decided upong the brightest frame..
meanOfThisFrame = mean(thisFrame);
imshow(thisFrame);
impixelinfo; % Let user mouse around and see (x, y, RGB)
axis('on', 'image');
caption = sprintf('The frame after is #%d and the mean is %.3f', max_brightness_image_frame + 1, meanOfThisFrame);
title(caption);
More Answers (1)
See Also
Categories
Find more on MATLAB Support Package for USB Webcams 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!