I've split a video into frames and written them to my disk individually. Now I need to find the difference between 2 consecutive frames. How do I call those images in he loop? The images are saved as Frame 0001.png, Frame 0002.png....etc

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 1월 31일

0 개 추천

I do that in my demo. Though I do the differencing as the frames are read in. In the latter half of the demo, after I've written out individual frames to individual files, I read in individual frames back in. You could of course switch the subtraction step to there if you want. See attachment (below in blue text).

댓글 수: 5

Sneheet
Sneheet 2014년 2월 1일
Image Analyst, I'm sorry, I'm quite new to matlab and image processing. Where exactly in your code are you finding the difference between frames?
See, I want to discard the frames which do not contain motion, so I find the frame differences. Is it possible to write those frames which contain motion into an array and then convert them into a new single video?
I would imagine that he does the differencing somewhere near the comment line,
% Now let's do the differencing
Sneheet
Sneheet 2014년 2월 1일
OK,fine. Now if I want to save certain frames to another location, how do I do that?
Shivaputra Narke
Shivaputra Narke 2014년 2월 1일
Go to matlab help and search for imwrite. If you are new to Matlab you can use Matlab help.
It's right there in the code. Take another look:
% Construct an output image file name.
outputBaseFileName = sprintf('Frame %4.4d.png', frame);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
% Extract the image with the text "burned into" it.
frameWithText = getframe(gca);
% frameWithText.cdata is the image with the text
% actually written into the pixel values.
% Write it out to disk.
imwrite(frameWithText.cdata, outputFullFileName, 'png');
You can make outputFolder whatever you want. For example I did this:
% Make up a special new output subfolder for all the separate
% movie frames that we're going to extract and save to disk.
% (Don't worry - windows can handle forward slashes in the folder name.)
folder = pwd; % Make it a subfolder of the folder where this m-file lives.
outputFolder = sprintf('%s/Movie Frames from %s', folder, baseFileName);
% Create the folder if it doesn't exist already.
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
But you could just replace that with your own folder:
outputFolder = 'd:\Narke\Images'; % Or whatever.
% Create the folder if it doesn't exist already.
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
If it's just certain frames, you can set outputFolder on a frame by frame basis inside the loop if you wanted to vary it by frame number or some other condition/criteria.

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

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2014년 1월 31일

댓글:

2014년 2월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by