How can i convert image sequence to video

조회 수: 35 (최근 30일)
alireza kooshafar
alireza kooshafar 2016년 10월 27일
댓글: Walter Roberson 2020년 9월 30일
i have 5 images and i want to see them as a video what should i do?
  댓글 수: 2
laurent jalabert
laurent jalabert 2020년 9월 30일
this program works very well. I will be happy to see improvements with sorting images by date/hour (this is not yet implemented, but very useful for me at least). I have image sequences that have filename like this 0_im.jpeg, 1_im.jpeg, ... 100_im.jpg. But classification in the list is 0_im, 100_im, 101_im,... 10_im, 110_im, 111_im, ...,
It should be 0_im, 1_im, 2_im ... 10_im, ... 100_im, 101_im ....

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

채택된 답변

Image Analyst
Image Analyst 2016년 10월 27일
See my attached demo that makes a movie from still frames. I use it to make a movie from a time lapse sequence that I'm making over several years of a gigantic new lab building that they're building outside my existing lab complex.

추가 답변 (6개)

Walter Roberson
Walter Roberson 2016년 10월 27일
편집: Walter Roberson 2016년 10월 27일
image_names = {'17.jpg', 'J83_9.tif', 'talk_normal.png', '18.jpg', 'eleventy seven puma divison (for real!).png' };
movie_obj = VideoWriter('TestMovie.avi');
for K = 1 : length(image_names)
this_image = imread(image_names{K});
writeVideo(movie_obj, this_image);
end
close(movie_obj);
  댓글 수: 2
Muzammil Ali
Muzammil Ali 2019년 2월 5일
Thank you for the above code. How can I add elapsed time caption to the video?
Image Analyst
Image Analyst 2019년 2월 5일
Use insertText() if you have the Computer Vision toolbox.

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


laurent jalabert
laurent jalabert 2020년 8월 5일
thank you so much, it works very well. I have just one concern : the images size is not kept when converting to video. Is there any way to keep image length/height constant, I mean similar to the origina image ?
  댓글 수: 2
Image Analyst
Image Analyst 2020년 8월 6일
Who are you asking? Why is your image size varying? If it does for some reason, then use imresize() to force it to a known size before calling writeVideo().
Walter Roberson
Walter Roberson 2020년 8월 6일
How are you creating the image? If you are using getframe() or similar to read the image from the display, then Yes, that is not going to be the same resolution as what you displayed.

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


laurent jalabert
laurent jalabert 2020년 8월 6일
편집: Walter Roberson 2020년 8월 6일
OK I got it at line 499 of your code :
% Define the output size
videoRows = 1458; %1080;
vidColumns = 1385; %1980;
startTime = tic;
I just input the size of my image that is the same for all image of my sequence, and that's it.
Yes, rather than input a constant at line 499, I can get the image info and pick up those vidRows and vidColumns
  댓글 수: 1
Image Analyst
Image Analyst 2020년 8월 6일
Does this mean that all the problems have been solved?

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


laurent jalabert
laurent jalabert 2020년 8월 6일
as you can see, I just found the lines defining the image size in the MakeVideo.m code, and modify accordingly to prevent distorsion of the image during the video creation.
I hope it could be helpful for other people as well.
From my side, I solved this problem of image distorsion, and the MakeMovie.m is working very well on Mac.
  댓글 수: 1
Image Analyst
Image Analyst 2020년 8월 6일
The comment says
% Define the output size
Is there something you think it should say instead? Or do you think the program should ask the user before the movie starts getting made? Like in an inputdlg() popup dialog box, or have edit fields for the width and height, and a checkbox for "Maintain aspect ratio" and determine the other dimension from the largest dimension?

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


laurent jalabert
laurent jalabert 2020년 8월 7일
well, usually, people who want to make a video from a sequence of photos, they are considering photos having similar length and width. So why not loading the first image, then get the image size, then update the line 499 accordingly. Then the output video will display exactly what the user want. He can resize his video later with maybe other software, but the base video will respect the initial image size, which is quite important I think.
another improvement is indeed to ask the user if he wants to downsize the image size (let's say if 1 image is 2Mo, then downsize options might allow smaller size. This is quite useful I think, otherzise, videos can reach several 100Mo for nothing. Just a kind of animated diaporama of this size is not so useful.
So the MakeMovie.m program is really fantastic right now, it works very well, and having those "standard" options below will make it perfect for the needs of many people.
I suggest to make a simplified version of this program, without the GUI interface, so that the code could be implemented in any other matlab program that does autamated jobs, output sequence of images or figures, then animate them with this short code.
I did several years ago, but I lost the code on old Mac computer that passed away recently ...
Thank you again for developing this code, it was really helpful to me.
  댓글 수: 1
Image Analyst
Image Analyst 2020년 8월 7일
laurent: thanks for your comments and good suggestions. The program was built when I was taking a photo of a building/wing being built/attached outside our existing building over 3 years. It was the largest building in the state even before the new addition, and now it's even larger! But the images were larger than HDTV (my computer resolution) and so I had to (or wanted to) downsize them.
It's always a balancing act between making code robust, flexible, powerful, and understandable as opposed to simple. Quite often I have people accept terrible, fragile code in Answers over my code because my code tends to look longer and more complicated/intimidating. For example, they will hard code in numbers while I'll put in a descriptive variable name to assign the parameter, making it more flexible. And I'll have comments to explain every step of the way (they won't). And I'll have lines of code to show pretty graphics/plots/images, which they won't, or will have less. And I'll put in robustness code, like popup a friendly message if the file they're looking for does not exist, rather than a cryptic red MATLAB error. So they think my code is harder when actually it's better, more robust (less fragile), and easier to read and understand. So sometimes it's not clear what people want. But thanks again for the comments. I'll take another look at improving the Movie Maker code.

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


laurent jalabert
laurent jalabert 2020년 8월 8일
thank you for your explanations, I think you'd better keep this code as it is, because it works well, and also it is quite general purpose. Maybe I might suggest to add some comment lines to explain how to use the histogram or draw lines and so on. I don't use it with your code, but I made a program several years ago dealing with same capabilities, with crop functions, histograms, image tracking region (ROI) and so on. It was to follow atoms motion from video made from Transmission Electron Microscope real time recording.
As I have some skills in Matlab, I could learn from your code in order to build up GUI which I am less familiar, so I would like to thank you very much for sharing your code, it is very helpful. In future, I will try to get inspired by this code, and make an application for my data analysis.
Usually, I write about 1000 lines of code to analyse scientific data in automated way, generating about 100 graphs that I ouput in a powerpoint, so I just need to be inspired by your code and adapt it to my application specific target, so that I could create a video sequence from the 100 graphs that I generate. That is why I add this issue regarding the length/height of figures.
Once again, thank you so much for those fruitful exchanges

Community Treasure Hunt

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

Start Hunting!

Translated by