简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM