我必须读入数百个TIFF文件,执行一些数学运算,然后输出一些内容。这是为成千上万的实例所做的。最大的瓶颈是imread。使用PixelRegion时,我只读入了文件的一部分,但速度仍然很慢。
目前,阅读部分在这里。
你能建议我如何加快速度吗?
for m = 1:length(pfile)
if ~exist(pfile{m}, 'file')
continue;
end
pConus = imread(pfile{m}, 'PixelRegion',{[min(r1),max(r1)],[min(c1),max(c1)]});
pEvent(:,m) = pConus(tselect);
end
发布于 2018-02-12 15:49:44
一般加速比
Parfor
以下解决方案假定您有权访问并行计算工具箱。我测试了10,840个tiffs,每个图像最初是1000x1000,但我只读取了其中300x300的部分。我不确定有多少个大的pConus(tselect)
,所以我只是存储了整个300x300的图像。
附言:很抱歉格式化的问题。它拒绝将其格式化为代码块。
基于我的2.3 GHz i7和16 my内存的结果
的时间
% Setup
clear;clc;
n = 12000;
% Would be faster to preallocate this, but negligeble compared to the
% time it takes imread to complete.
fileNames = {};
for i = 1:n
name = sprintf('in_%i.tiff', i);
% I do the exist check here, assuming that the file won't be touched in
% until the program advances a files lines.
if exist(name, 'file')
fileNames{end+1} = name;
end
end
rows = [200, 499];
cols = [200, 499];
pics = cell(1, length(fileNames));
tic;
parfor i = 1:length(fileNames)
% I don't know why using the temp variable is faster, but it is
temp = imread(fileNames{i}, 'PixelRegion', {rows, cols});
pics{i} = temp;
end
toc;
https://stackoverflow.com/questions/48679414
复制相似问题