MATLAB: Optimal strategy for loading in many tiffs and resaving as imageJ tiff stacks

tiffs speed

Hey there,
I have some large video stored as tiff images (50,000+ frames), save in a folder as a set of individual tiff images. I want to "repackage" these folders so that they contain stacks of 500. I've started to do this using imread, but I am wondering what the fastest way(s) to do something like this are. Thanks!

Best Answer

Ok, if you are just moving files from one folder to another you can do it at the command prompt, you don't really need matlab. But anyway, let's say you want to do it in matlab.
I am assuming that you are at the folder that your 50k+ frames each stored as a tiff image is stored. And you want to move them to subfolders within the same folder called p1 to pn where p1 stores tiff1 to tiff500, and p2 stores tiff501 to tiff1000 and so on.
Here is the code:
n=500;
fileList=dir('*.tiff');
% NOTE adjust the extension to tif or tiff based on what you have
nFiles=numel(fileList);
nFolders=ceil(nFiles/n);
fileList=struct2cell(fileList);
fileList=fileList(1,:);
for i=1:nFolders
folderName=['p' num2str(i)];
mkdir(folderName);
func=@(x) ( copyfile(x,folderName) );
startFile=(i-1)*n+1;
endFile=min( i*n, nFiles);
cellfun(func,fileList(startFile:endFile));
end