Image Sequences to video conversion in matlab - matlab

I have to convert image sequences to a video using 'matlab R2010a' version. What function should I use to load images to a video? In 'Matlab R2013a' version, 'writeVideo' is used. What is the related function of 'writeVideo' in 'R2010a' version?

If your images are created by some Matlab code, then you can always save them as image files (check out the print function), and use some utility (like VirtualDub) to convert the image files to video.
If it is enough to play the image sequence without saving it, then use the movie function.

Related

How to perform 'ouroboros' recursive effect on PNG deepdream image (already rendered) as GIF output

Need help/assistance. Trying to perform this in colab. I have a script that creates deepdream outputs as PNG files but want to take those files and apply an 'infinite ouroboros' recursive effect and output as a GIF, is this possible from a single static high resolution PNG image?

Preserving MP4 quality when using VideoWriter in MATLAB [duplicate]

I need to get an mpeg4 file to use in another application, from an original mpeg4 video I loaded into matlab and edited (frame by frame).
To do so, I tried using VideoWriter, setting the quality to 100%:
newVid = VideoWriter(outputfilename, 'MPEG-4');
newVid.FrameRate = fps;
newVid.Quality = 100;
However, the result I'm getting is very poor and if the original unedited video size was ~50MB, the one I get post-edit in matlab is around ~20MB, and I don't know how to keep the quality and size as they were.
I also tried saving as .avi and converting to mpeg4 with ffmpeg, but it gave even poorer results.
Any ideas?
MPEG-4is a compressed format so there is information loss when you save it in this format. Quality is the quality of the compression but you do not want any compression. To force Matlab not to use compression my guess is to use the statement below as the default is H.264
newVid.VideoCompressionMethod = 'none'

Making the "Region of Interest" (ROI) transparent in MATLAB

I've already made a function to cut out the image, and the part I cut out has a black background. I'm trying to make the black part transparent, then I can generate an image sequence that I can create a video with. I've tried converting the image to a double and then replacing the 0 values with NaN:
J = imread('imgExample.jpg');
J2 = im2double(J);
J2(J2 == 0) = NaN;
imwrite(J2, 'newImg.jpg');
but when I convert it into a video, it doesn't seem to stay. Is there any way to get the black part of the image to be transparent?
From clarifications in comments, you are trying to create a video format that supports alpha transparency using matlab.
In general this seems impossible using matlab alone (at least in matlab 2013 which is the version I use). If you'd like to check if the newest matlab supports videos with alpha transparency, type doc videowriter and have a look at the available formats. If you see anything with transparency options there, take it from there. But the most I see on mine is 24bit RGB videos (i.e. three channels, no transparency).
So matlab does not have the ability to produce native .avi video with alpha transparency.
However, note that this is a very rare video format anyway, and even if you did manage to produce such a video, you would still have to find a suitable viewer which supports playing videos with transparency!
It's therefore important for you to tell us your particular use-case because it may be you're actually trying to do something much simpler (which may or may not be solvable via matlab) (i.e. a case of the XY Problem
E.g. you may be trying to create a video with transparency for the web instead, like here https://developers.google.com/web/updates/2013/07/Alpha-transparency-in-Chrome-video
If this is the case, then I would recommend you attempting the method outlined there; you can create individual .png "frames" with transparency in matlab using the imwrite function. have a look at its documentation, particularly the section about png images and the 'Alpha' property. But beyond that, you'd need an external tool to combine them into a .webm file, since matlab doesn't seem to have a tool like that (at least none that I can see at a glance; there might be a 3rd-party toolkit if you look on the web).
Hope this helps.

Cutting part of image and saving to file in MATLAB

Lets assume i have image 'image.jpg'.
I want to choose part of it with imrect function, and save to new file 'newimg.jpg'.
Do you have any idea how to implement in a simple way?
Thanks.
Use the imcrop function to cut out the region, and then imwrite to save it into a separate image.

How to generate a video from matlab without codec errors?

Using my Windows 7 64bit machine, I'm trying to generate an avi file from Matlab using the sequence
aviobj = avifile('test.avi', 'fps', 25);
% a loop of aviobj = addframe(aviobj, frame)
close(aviobj)
However, the file generated is corrupt - with VLC it looks sheared and with bad colors, with Media Player it was a black screen, and with Divx Plus player it looks okay but generates a warning.
I've tried specifying other codec types (via avifile('test.avi', 'fps', 25, 'compression', 'TYPE') but Matlab never seems to be able to find that codec - I've tried Indeo and cvid and MSVC and MRLE and many more, but Matlab just generates a "not a supported compression method" warning, and then outright fails when addframe is invoked.
How can I solve the above problem, or alternatively, is there a different, simple way to just generate an avi by adding a frame at a time?
How to generate a video from matlab without codec errors?
try to use mmwrite
http://www.mathworks.com/matlabcentral/fileexchange/15881-mmwrite
Well after a few more searches online and experimentation, looks like others have encountered this problem as well, and suggested just using a different program to compress it and that should also fix the file, so that's what I did:
Generated an uncompressed file
Opened it in VirtualDub(good open-source video software which doesn't require installation)
From the video menu I chose "compression" and selected the "Microsoft Video 1" option
Saved the file via the save-as menu option
It now looks correct in all the players I've tried, and the file is smaller in size.
What you are describing what happens in VLC is probably related to having a resolution that is not supported by the codec. Try resolutions that are multiples of 2,4,8,16 and see what works. VirtualDub probably takes care of that somehow.
Otherwise it's really simple. All you have to do:
aviobj = avifile('example.avi', 'compression', 'none', 'fps', 25);
for i=1:1000
%generating the filenames
filename = strcat(FolderName,'/frame', sprintf('%05d', i),'.bmp');
I = imread(filename);
aviobj = addframe(aviobj,I);
end;
aviobj = close(aviobj);
I know I am replying to a very old thread, but I helped my brother with this and learned a few things that might help others:
My brother had a very small video, the result of an MRI scan, 51x51 pixels. Using VideoWriter with profile "Uncompressed AVI" worked, but did not play well in VLC. Virtualdub also threw errors.
What fixed it, is making sure that the video dimensions where a multiple of 2.
A 96x96 video played fine and could also be transcoded to XVID in virtualdub.
Also, with very small videos, set the video output mode to wingdi in VLC. With OpenGL or Direct3D and overlay mode, the GPU will do the scaling and interpolate pixels in between.