Interpolate a 4D matrix to increase its size

Hi!
i have a 4D matrix B its size is 40*64*40 and i want to increase it to be 250*400*250 ,i know that if we multiplie the first size with 6.25 we will get the final size that we want, i know i should use the interp3 for that ,i tried it i did [X,Y,Z]=size(B);
V=6.25*size(B1);
[Xq,Yq,Zq]=[250 400 250];
B1=interp3(X,Y,Z,V,Xq,Yq,Zq);
But it dosen't work . please can any one help me with that ? specialy that i am not used to work with 4D matrix ,I used to use imresize() for 2D matrix!!
thank you so muchh

4 Comments

A "4D" matrix should have 4 dimensions, not 3. I assume, you mean a "3D array".
"It doesn't work" is a lean description of what happens. Please mention, what you observe and what you want instead.
i have a 4D matrix with X Y Z and T but i want just to change the first 3 dimensions and keep the fourth one.
"i have a 4D matrix B its size is 40*64*40"
That is a 3D array (unless you are bothering to arbitrarily count one implicit trailing singleton dimension). Why do you keep insisting that an array with three consecutive non-singleton dimensions is a "4D matrix" ?
in fact i have an image 4D 40*64*40*8 ( it s an IMR image 8 means the number of canals tha we have ) , i just didnt explain the situation in a good way.at the end i changed the dimension

Sign in to comment.

 Accepted Answer

Jan
Jan on 26 Apr 2019
Edited: Jan on 26 Apr 2019
[X,Y,Z] = size(B);
B1 = interp3(1:X, 1:Y, 1:Z, B, ...
linspace(1, X, 250), ...
linspace(1, Y, 400), ...
linspace(1, Z, 250));

3 Comments

HI Jan thank you for your help but i got an error as (Error using permute
ORDER must have at least N elements for N-D array
error in iterp3 v=permute(v,p);
is that could be because my matrix is 4D dimension but i am intrested in the first 3 dimension the fourth one i dont want to change it
HI thank you i found my error in fact i should not neglige the fourth dimension
Yes, if B has 4 dimensions, you have to consider this explicitly. Simply use interpn:
[X,Y,Z,T] = size(B);
B1 = interp3(1:X, 1:Y, 1:Z, 1:T, B, ...
linspace(1, X, 250), ...
linspace(1, Y, 400), ...
linspace(1, Z, 250),
1:T); % Last dimension untouched

Sign in to comment.

More Answers (2)

B1=imresize3(B,[250,400,250]);

3 Comments

Hi
thank you for your answer i already tried this function but matlab dosent reconize it , it gives me undefined function or variable and he suggested imresize()
HI thank you i found my error in fact i should not neglige the fourth dimension
Jan
Jan on 29 Apr 2019
Edited: Jan on 29 Apr 2019
The documentation of imresize claims, that "any dimension" is handled, but some tests show, that this concerns 2D gray-scale images and [X * Y * N] arrays only, while for the later only the 1st 2 dimensions are scaled and the last one is treated as color channels.

Sign in to comment.

Matt J
Matt J on 29 Apr 2019
Edited: Matt J on 29 Apr 2019
If your data truly does have 4 dimensions, then you can use imresizen
B1=imresizen(B,[6.5,6.5,6.5,1]);

Asked:

on 26 Apr 2019

Edited:

on 29 Apr 2019

Community Treasure Hunt

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

Start Hunting!