MATLAB: How to save series of images

savingseries of imagesworkspace

Hi.
I am reading and doing a bunch of stuff on a series of images.
But I want to save every thing done on every image for future use. How can I do so?
I mean, for example, I have read 100 images and just turn them into binary. How can I save all of them in binary in the workspace for further use?
By saving I do not mean writing the images, I mean keep them in the memory and workspace.
I can't use something like
. . .
binaryImage (i) = … (i is the index of the loop in which the process is done)
because it confuses with dimensions of the image.
What can I do?
Thanks a lot.

Best Answer

Steven/Mohammad:
If you have a script, then any variables are left hanging around in the base workspace. If they are in a function, then vanish when the function exits. To use variables in a function in the future elsewhere, you need to return them as output arguments. Or else use the methods described in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
By the way if you want to save images in a loop, you need to save either to a 3D array
if i == 1
binaryImage3D = thisBinaryImage; % The first time, initialize
else
binaryImage3D = cat(3, binaryImage3D, thisBinaryImage);
end
or save it into a cell of a cell array where you use braces instead of parentheses.
allBinaryImages{i} = thisBinaryImage;
You can read the FAQ on cell arrays for a good description of cell arrays: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F