How does one rescale an array of 3D images in MATLAB R2011b?
1 view (last 30 days)
Show older comments
MathWorks Support Team
on 25 Jan 2013
Edited: MathWorks Support Team
on 1 Aug 2016
I'm trying to rescale a 512 x 512 x 56 3-d image array which has physical dimensions of 0.07 cm in the x and y directions and 0.13 in the z direction, so that the physical dimensions in each direction are the same. I can't figure out the way to do it. I was thinking of the "maketform" command with the 'box' option, but I can't find an example of how to specify the arguments with this option. Do you have any suggestions?
Accepted Answer
MathWorks Support Team
on 1 Aug 2016
This can be done in 2 ways:
1) Using a combination of MAKETFORM, MAKERESAMPLER and TFORMARRAY.
Please refer to the documentation for TFORMARRAY for for information:
<http://www.mathworks.com/help/images/ref/tformarray.html>
2) You can also do this using the INTERP3 or GRIDDEDINTERPOLANT functions. These are effectively the same under the hood.
Please refer to the following documentation for more information of GRIDDEDINTERPOLANT:
<http://www.mathworks.com/help/matlab/ref/griddedinterpolantclass.html>
the following code demonstrates this:
%%Creates a 3D image
A = imread('eight.tif');
for j=1:10
A(:,:,1+j)=A(:,:,1)-20*j;
end
RFactor=2;
%%Using TFORMARRAY
T=maketform('affine',[RFactor 0 0 0; 0 RFactor 0 0; 0 0 RFactor 0; 0 0 0 1]);
R = makeresampler('cubic', 'bound');
TSIZ_IN=size(A);
TSIZ_OUT=ceil(TSIZ_IN.*RFactor);
OUTIMG=tformarray(A,T,R,[1 2 3],[1 2 3],TSIZ_OUT,[],[]);
%%Using INTERP3
[sy sx sz]=size(A);
[X,Y,Z]=meshgrid(1:sx,1:sy,1:sz);
[X2,Y2,Z2]=meshgrid(1:1/RFactor:sx,1:1/RFactor:sy,1:1/RFactor:sz);
OUTIMG2=interp3(X,Y,Z,single(A),X2,Y2,Z2,'Cubic');
OUTIMG2=uint8(OUTIMG2);
0 Comments
More Answers (0)
See Also
Categories
Find more on Convert Image Type 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!