imwarp large image running out of memory

3 ビュー (過去 30 日間)
holly38
holly38 2019 年 4 月 3 日
回答済み: Bjorn Gustavsson 2019 年 4 月 3 日
Hi,
I am trying to imwarp a very large image (10722 by 120908... a tif file: 3.6GB), and am constantly running out of memory... does anyone know how to imwarp a big tif?
I'm running Matlab 2018a on my linux server (debian), using an interactive session with 24 cores. I have quite a lot of available memory. Using this approach (http://tipsarea.com/2015/04/21/how-to-find-out-available-memory-for-matlab-in-linux/) apparently I have 180GB (sounds strangely high).
ulimit = unlimited
I can load this image into memory using imread. The command where it fails:
tif_warp = imwarp(tif_in, tform, 'OutputView', imref2d([imgsz(1,1) imgsz(1,2)]) ) ; % warp to remove polynomial film distortion
where tform:
---
tform =
PolynomialTransformation2D with properties:
Degree: 4
A: [1.4314e-13 1.0000 7.2174e-13 -5.0692e-15 -3.1960e-15 -1.1230e-11 4.3018e-15 -1.0182e-13 3.2965e-16 -2.7476e-11 -9.6678e-16 4.3561e-14 1.8003e-13 1.6145e-16 2.2388e-10]
B: [-0.0012 2.5527e-04 0.9999 -3.5316e-05 0.0013 -0.0263 -1.1529e-05 -1.4097e-05 -9.0935e-05 0.0031 6.6055e-06 4.4793e-06 7.7872e-04 -1.1722e-04 0.1289]
Dimensionality: 2
---
Error Message:
---
Error using horzcat
Out of memory. Type HELP MEMORY for your options.
Error in images.geotrans.PolynomialTransformation2D/getTerms (line 262)
X = [ones(M,1), x, y, x.*y, x.^2, y.^2, ...
Error in images.geotrans.PolynomialTransformation2D/transformPointsInverse (line 218)
X = self.getTerms(xy);
Error in imwarp>remapAndResampleGeneric2d (line 557)
[srcXWorld,srcYWorld] = tform.transformPointsInverse(dstXWorld,dstYWorld);
Error in imwarp>remapPointsAndResample (line 241)
outputImage = remapAndResampleGeneric2d(inputImage,R_A,tform,outputRef,method,fillValues, SmoothEdges);
Error in imwarp (line 226)
outputImage = remapPointsAndResample(parsedInputs.InputImage,R_A,tform,outputRef,method,fillValues, SmoothEdges);
---
I didn't find the HELP MEMORY advice very helpful... does anyone know of any way to warp a very large tiff when memory is an issue? I couldn't get blockproc to work either.
Cheers

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 4 月 3 日
Maybe you can get weasle your way around the problem by divide-and-conquer? Would it work if you applied your warping on a sub-sampled image in such a way that you would get the warped coordinates for the transformed pixels and then use one of the scattered interpolation functions to do the warping of your full image part-by-part. I know that this is essentially rewriting the functionality of imwarp, but if nothing else work. (To me it was not obvious that it would be possible to warp parts of your image step by step with imwarp - maybe it is, maybe it is possible to write a modified version of imwarp where you can do that, maybe you can apply imwarp on a subsampled image and determine the displacement field, such a displacement field should be possible to up-sample/reinterpolate and then use parts of that and your full image). Not much of a solution but maybe you get an idea.
HTH

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by