How to achieve a faster 3D Translation?
4 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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
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
More Answers (1)
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);
0 Comments
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!