0

I have a 3D mask volume L with the following:

print(L.shape)
(170, 256, 256)
print("L: ", np.unique(L))
L: [0 1 2 3 4 5 6 7 8]

enter image description here
I want to downsample and then upsample the mask to its original size keeping the label values the same.
Failed attempt->Downsampling:

from scipy.ndimage.interpolation import zoom
zL = zoom(L, (0.5, 0.5, 0.5), mode='nearest')
print("zL: ", np.unique(zL))
zL:  [-3 -2 -1  0  1  2  3  4  5  6  7  8  9 10]

enter image description here
which is changing the label values. I have tried with other mode options such as constant and all. But none seems to work.

Successful attempt->Downsampling: On the other hand:

dx = 2
dy = 2
dz = 2
if DOWNSAMPLE:
    L_down = L[::dx, ::dy, ::dz]
print("L_down: ", np.unique(L_down))
L_down:  [0 1 2 3 4 5 6 7 8]

seems to work without changing the label values.

enter image description here
Failed attempt->Upsampling: But when going back to original size with

zL = zoom(L_down, (2, 2, 2), mode='nearest')

did not work. Also if there are any other details about trilinear interpolation or so would be appreciated.
Thanks.

banikr
  • 11
  • 4

0 Answers0