MATLAB: Openning 14000 tif files…

imreadrtifctif

Hello,
I am trying to optimize the time taken to open ~14000 tif files of about 400KB each.
I have tried different approaches essentially based on killing what I do not need and monitoring that with the profiler. But the results seem inconsistent from one run to another.
Essentially my test is the following: I evaluate 3 different ways of operating (from the worst to the best I hope…), for the last ones I have copied rtifc.mexw64 in the current folder.
%%imread
im = zeros(424,424,14000,'uint16');
tic
for k = 1:length(fname)
tmpf = [Folder fname{k}];
tim = imread(tmpf);
im(:,:,k) = tim;
end
T = toc;
[T T/14]
clear im tim tmpf
%%feval tifread
im = zeros(424,424,14000,'uint16');
tic
tf = imformats('tif');
for k = 1:length(fname)
tmpf = [Folder fname{k}];
tim = feval(tf.read, tmpf,1 );
im(1:424,1:424,k) = tim;
end
T = toc;
[T T/14]
clear im tim tmpf
%%rtifc
im = zeros(424,424,14000,'uint16');
tic
tmp.index =1;
tmp.PixelRegion = {[1 424],[1 424]};
tmp.info = imfinfo([Folder fname{1}]);
for k = 1:length(fname)
tmp.filename = [Folder fname{k}];
[tim,trash1,trash2] = rtifc(tmp);
im(1:424,1:424,k) = tim;
end
T = toc;
[T T/14]
clear im tim tmpf
From there I have 2 points:
1. There is no big improvement between the 3…
  • 70s 67s 66s
  • 69s 63s 64s
  • 66s 64s 61s
2. From one run to another I have sometime massive differences for the 3 methods: 29s 18s 16s
Do you have any suggestion? What am I doing wrong? THANK YOU!!! 🙂

Best Answer

Part of the time in reading is getting the files into operating system memory cache. If you have read moderately sized files recently, then you might not be necessary to fetch them from hard disk to main memory; instead a memory-to-memory copy might be all that is needed.
Related Question