Increase speed of imwarp

6 views (last 30 days)
Jaime
Jaime on 7 Mar 2014
Answered: Kees de Kapper on 21 Mar 2018
Dear Matlab community
I have been using imwarp to spatially transform CT-images along with an upscaling step. I would like to optimize my code and I've found that imwarp is taking a lot of time for my needs. Since I need to upscale one of the images by about 2x2x3 in the x,y, and z direction, respectively, the function ends up taking around 10 minutes per image. After doing a profile check it is actually interp3 the one function inside imwarp that consumes most of the time. I wonder if there are ways to speed imwarp like using parallel computing or other alternatives.
Best regards, Jaime
  1 Comment
Igor Reidler
Igor Reidler on 23 Aug 2015
Hi Jaime, I'm facing a similar situation. Was wondering if you had any progress using parallel computing toolbox, GPU computing, or other?
Thanks, Igor.

Sign in to comment.

Answers (2)

Matt J
Matt J on 23 Aug 2015
IMWARP seems like the wrong tool for upsampling images. griddedInterpolant is probably smarter, in the sense that it knows that the upsampling can be done separably, and hence more efficiently:
[m,n,p]=size(CTVolume);
gridVectors={linspace(1,m,2*m),...
linspace(1,n,2*n),...
linspace(1,p,3*p)};
F=griddedInterpolant(CTVolume);
newImage=F(gridVectors);

Kees de Kapper
Kees de Kapper on 21 Mar 2018
Dear all,
I know this thread is a bit "old" but I've got a similar question. I'm using imwarp for extracting a 2D image from a 3D dataset but with the use of a 3D transformation.
What I experienced is that the speed of imwarp does not depend on the size of the resample output but on the size of the input image. This surprised me a lot and implies a very inefficient implementation.
I found by searching the web, the function tformarray that I might use as well. Using this function the calculation time is reduced with a factor more than ten. I find this very surprising as I expect the imwarp function is build on top of the tformarray-function (correct me if I'm wrong). Do I make a mistake?
The disadvantage is that when using tformarray, I have to construct a tmap_B that reflects the pixel index corresponding to the axis coordinates for both input and resample axis. Although this might be trivial, is there a in-build Matlab function that can do the job?
I'm looking forward to your comments.
Many thanks in advance,
Kees

Tags

Community Treasure Hunt

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

Start Hunting!