필터 지우기
필터 지우기

How to sum up about 3-4 color frames and only show the brightest frame. Matlab

조회 수: 4 (최근 30일)
obj = VideoReader('C:\Users\Robotics\Pictures\Saved Pictures\Lightfile\Prelight.MOV');
for img = 1:obj.NumberOfFrames;
filename = strcat('frame',num2str(img),'.jpg');
b = read(obj,img);
imwrite(b,filename);
end
I have this code that reads the file and get all frames, but I need it to sum up about 3-5 frames then take the brightest frame and store it. Can someone help please!!
  댓글 수: 2
OCDER
OCDER 2017년 9월 27일
편집: OCDER 2017년 9월 27일
Can you explain what you mean to "sum up 3-5 frames and take the brightest frame"? The sum of 3-5 frames will always be the brightest frame.
Since an image is a matrix, you can simply add images together using matrix math, but use double format (im2double) so that the sum of 3-5 images doesn't exceed the maximum value given a number format (ex: uint8 max value is 255). Rescale all image intensities at the end to prevent flickering effects by inconsistent rescaling.
Marqual Brown
Marqual Brown 2017년 9월 27일
Okay, so if I have a video and its 30 seconds long with a flashing light going on and off . I would like the program to capture the frame when the light flashed then output the light that flashed. Each flash is going to have 10-12 frames with the light on but I want to capture the brightest frame of light.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 27일
편집: Walter Roberson 2017년 9월 28일
The below code assumes that the frames are RGB.
The below code does not attempt to detect intervals of flash and determine the best out of the interval: it takes the frames frames_per_group at a time and determines the brightest of that group.
obj = VideoReader('C:\Users\Robotics\Pictures\Saved Pictures\Lightfile\Prelight.MOV');
frameidx = 0;
frames_per_group = 5;
frame_history = [];
frameidx_history = [];
while hasFrame(obj)
frameidx = frameidx + 1;
groupidx = groupidx + 1;
b = readFrame(obj);
frame_history = cat(4, frame_history, b);
frameidx_history(end+1) = frameidx;
if size(frame_history, 4) == frames_per_group
maxbrightness = -inf;
maxbrightnessidx = -inf;
for K = 1 : frame_per_group;
grayframe = rgb2gray(frame_history(:,:,:,K));
thisbrightness = sum(grayframe(:));
if thisbrightness > maxbrightness
maxbrightness = thisbrightness;
maxbrightnessidx = K;
end
end
bestframe = frame_history(:,:,:,maxbrightnessidx);
bestframeidx = frameidx_history(maxbrightnessidx);
filename = sprintf('frame%04d.jpg', bestframeidx);
imwrite(bestframe, filename);
frame_history = [];
frameidx_history = [];
end
end
(Code not tested)
  댓글 수: 8
Marqual Brown
Marqual Brown 2017년 9월 29일
I have another question, could this also work for an 360 degree camera!!
Walter Roberson
Walter Roberson 2017년 9월 29일
I do not know how a 360 degree camera might differ from a regular camera ? Is it just like a fish-eye lens with a single image, or is it multiple images at the same time?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Camera Calibration에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by