Saving a sequence of images

So further to my image processing:
I am reading a video file frame by frame. converting each frame to grayscale, zero'ing all values below 254 in the intensity matix, and then adding these images ontop of on another to build up a kind of time based image showing all the zones a particular event occured.
What I want to do now is save that resulting image after the addtion of each frame so that I end up with a folder full of images, the same number of images that made up the original film. Then I want to assemble them into a movie.
How do I save a sequence of images with a incrementing file name? i.e.
pic1.jpg pic2.jpg pic3.jpg .... pic(x).jpg
?
how do I append that incrementing count number, x, onto the end of the filename?
I tried this
imwrite(Sum,'C:\Documents and Settings\mmam16\My Documents\MATLAB\Pic#%d.jpg',x)
but I dont really know what the #%d does.

 Accepted Answer

Alex, you were close.
IMWRITE accepts a string name for the file, it does not know how to insert 'x' into the name. So you should create a string with the file name you want before passing it to IMWRITE:
filename = sprintf('c:\all that\Pic%d.jpg', x);
imwrite(data, filename);
More info here
You can also look at the doc for sprintf for various formatting options (like say zero padding the number).

5 Comments

hmm I keep getting this error
??? Error using ==> imwrite at 453
Can't open file "C:" for writing.
You may not have write permission.
Error in ==> video2 at 38
imwrite(Sum, filename,'jpg');
dont have permission to write to my own documents folder? lol
also says I have an invalid escape sequence. Something to do with my x a the end of the filename sring
oh got it, have to have \\ for back slashes
or else it just thinks you want to save to C: and thats it
i have to save the frame one by one
e.g. 1.1.jpg
1.2.jpg
1.3.jpg
how i can save the frame ... need help
i need help, if you figured it out, please.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!