How to achieve a faster 3D Translation?

1 view (last 30 days)
I'm making a GUI to allow a user to do image translation on set of 3D image data.
I want the user to be able to visually see the effects of the shift (using XY, XZ, and YZ slices).
I've tried this for 3D:
% 3D transform:
trslt = [eye(3) xyz'; 0 0 0 1]';
tform = maketform('affine', trslt);
data = tformarray(data, tform, rsmp, [2 1 3], [2 1 3], sizXYZ([2 1 3]), [], 0);
However, performing the following 2D operations runs in a fraction of the time:
xyTform = maketform('projective',[1 1; 1 sizY; sizX 1; sizX sizY],[1+x 1+y; 1+x sizY+y; sizX+x 1+y; sizX+x sizY+y]);
zTform = maketform('projective',[1 1; 1 sizY; sizZ 1; sizZ sizY],[1+z 1; 1+z sizY; sizZ+z 1; sizZ+z sizY]);
data = tformarray(data, zTform, rsmp, [3 1], [3 1], sizXYZ([3 1]), [], 0);
data = tformarray(data, xyTform, rsmp, [2 1], [2 1], sizXYZ([2 1]), [], 0);
Is there any better (or faster) way to do this?
Edit: Just to clarify, I'm using this transform to allow shifting by "fractional" pixel amounts. I know this would be easier if shifting by whole pixels.

Accepted Answer

Sean de Wolski
Sean de Wolski on 28 Jan 2013
You may be able to get better speeds with griddedInterpolant(), especially if you have to do this multiple times at the same query points.
  3 Comments
Sean de Wolski
Sean de Wolski on 28 Jan 2013
I don't believe so in R2012b. However, the R2013a Prerelease, available to customers with an SMS subscription, might interest you.
Also note, that on the image edges, you are no longer interpolating but extrapolating. You may wish to prepad your image before doing the transformation.
I never did ask, how long is tformarray() actually taking and how big are your images?
For a 1000x1000x5 it's taking only 1.5-2s on my machine:
A = rand(1000,1000,5);
tic
A2 = imtranslate(A,[1.48 pi -2.3]);
toc
Christopher
Christopher on 28 Jan 2013
Edited: Christopher on 28 Jan 2013
I'm using DICOM image data from a PET/MR scan. Matrix size is 377x377x127
It takes ~8 seconds on my machine for two 2D transforms and ~20 seconds for a 3D transform.
It's only taking ~2-3 seconds to use griddedInterpolant().
I may try the R2013a Prerelease.

Sign in to comment.

More Answers (1)

vishal
vishal on 5 Jun 2015
hello christopher, how did you read dicom image? is there any direct command to get matrix size like 377*377*127 ? or you resized the image to get 3d array?? like the given code??? fid = fopen('1.im','r'); %got to the first byte after the header status = fseek(fid,1024,'bof'); %read the data data = fread(fid); %close the file fclose(fid); %reshape the data into a 3D array data3d = reshape(data,128,128,128);

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!