我正在尝试编写一个多页 tiff 文件,它是 128 像素 x 128 像素 x 122000 帧的 16 位无符号整数。ImageJ 或简短的 Python 脚本可以在不到一分钟的时间内在快速机器上完成此操作。在同一台机器上,使用我尝试过的任何方法,MATLAB 可能需要几天时间才能完成。这是我迄今为止尝试过的:
使用 imwrite 将 IMG 写入 test.tif(MATLAB 文档推荐)
tic
numframes=size(IMG,3);
divider=10^(floor(log10(numframes))-1);
imwrite(IMG(:,:,1),'test.tif');
for i=2:numframes;
imwrite(IMG(:,:,i),'test.tif','WriteMode','append');
if (round(i/divider)==i/divider)
fprintf('Frame %d written in %.0f seconds, %2d percent complete, time left=%.0f seconds \n', ...
i, toc, i/numframes*100, (numframes - i)/(i/toc));
end
end
Run Code Online (Sandbox Code Playgroud)
这导致以下输出:
第 10000 帧在 104 秒内写入,8.196721e+00% 完成,剩余时间=1163 秒 20000 帧在 296 秒内写入,1.639344e+01% 完成,剩余时间=1509 秒 30000 帧写入 5.4509%,296 秒完成,剩余时间=1809 秒 40000 帧用 1035 秒写入,3.278689e+01% 完成,剩余时间=2121 秒 …