How can I read a subsection of tif files for faster import?

孤街浪徒 提交于 2019-12-13 05:52:20

问题


I need to read thousands of TIF files (3500x3500 in size) in a loop.

And imread is the biggest bottleneck. I only work on a small section of the image for which I have the row-col extent.

Is there anyway to import a subsection of the image to improve the import process substantially? Any other suggestions?

This is the import section of the code:

for m = 1:length(pFileNames)
    if ~exist(precipFileNames{m}, 'file')
        continue;
    end
    pConus = imread(pFileNames{m});
end

P.S. I tried to use PixelRegions. But I have Matlab 2014, and I get this error:

Undefined function or variable 'PixelRegion'.

回答1:


Consider using vips at the commandline to extract the area you want from each image with a command like:

vips extract_area INPUT.TIF OUTPUT.TIF left top width height

Then combine that with GNU Parallel to do 4 or 8 at a time, something like this:

parallel vips extract_area {} sub_{} left top width height ::: *.tif

I suggest you make a backup before you start experimenting...

Benchmark Timing

I created 1,000 TIF images of random data, all sized at 3,500x3500 pixels and then ran the GNU Parallel + vips command above to extract an area of 100x100 pixels from each of the 1,000 TIFs.

On a reasonable spec iMac, the 1,000 sub images were extracted and written to disk in 11 seconds.



来源:https://stackoverflow.com/questions/37334444/how-can-i-read-a-subsection-of-tif-files-for-faster-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!