首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何在Matlab中更快地读取一堆TIFF文件?

如何在Matlab中更快地读取一堆TIFF文件?
EN

Stack Overflow用户
提问于 2018-02-08 06:59:14
回答 1查看 396关注 0票数 0

我必须读入数百个TIFF文件,执行一些数学运算,然后输出一些内容。这是为成千上万的实例所做的。最大的瓶颈是imread。使用PixelRegion时,我只读入了文件的一部分,但速度仍然很慢。

目前,阅读部分在这里。

你能建议我如何加快速度吗?

代码语言:javascript
运行
AI代码解释
复制
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
EN

回答 1

Stack Overflow用户

发布于 2018-02-12 15:49:44

一般加速比

  • 像素区域似乎不会在每次迭代中发生变化。我不能完全确定Matlab是否会优化最小和最大调用(尽管我很确定它不会)。如果您不在每次迭代中更改它们,请将它们移到for循环之外并计算一次。

Parfor

以下解决方案假定您有权访问并行计算工具箱。我测试了10,840个tiffs,每个图像最初是1000x1000,但我只读取了其中300x300的部分。我不确定有多少个大的pConus(tselect),所以我只是存储了整个300x300的图像。

附言:很抱歉格式化的问题。它拒绝将其格式化为代码块。

基于我的2.3 GHz i7和16 my内存的结果

  • for: 130秒
  • parfor:26秒+启动池

的时间

% Setup

代码语言:javascript
运行
AI代码解释
复制
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;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48679414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档