Problems with obtaining and saving 2D slices from a 3D array

I'm trying to save a 2D slice of a 3D array that I'm slicing with the following code:

import nibabel as nib
import numpy as np
from nibabel.testing import data_path
import os

vol1= np.load("teste01.npy")
zSlice= (vol1[1, :, :]).squeeze()
print (zSlice.shape)
np.save(zSlice, os.path.join("D:/Volumes convertidos LIDC/slice01.npy"))

I'm getting an error: TypeError: expected str, bytes or os.PathLike object, not ndarray

Is there any way to fix this? I need 2D arrays in order to be able to insert my images into an automatic lung vessel segmentation model but I only have 3D images, is there any way to obtain all the slices from said 3D image instead of slicing it manually (like I'm trying to do?

Upvotes: 1

Views: 285

Answers (1)

SebDieBln
SebDieBln

Reputation: 3459

You just mixed up the parameters for numpy.save. Use the filename as the first parameter and the data as the second:

np.save(os.path.join("D:/Volumes convertidos LIDC/slice01.npy"), zSlice)

Upvotes: 1

Related Questions