我将读取一个 nifti 图像并更改体素的值并保存与主图像类似但只有不同体素值的新 nifti 图像。换句话说,我希望分割图像中的标签从 0 到 7,而不是具有不同的数字。o 编写了下面的代码,但我收到此错误:
NotImplementedError: Wrong number or type of arguments for overloaded function 'WriteImage'.
可能的 C/C++ 原型有: itk::simple::WriteImage(itk::simple::Image const &,std::string const &,bool) itk::simple::WriteImage(itk::simple::Image const &,std::vector<std::string,std::allocator<std::string >> const &,bool)
编码:
对于 os.listdir(path) 中的 image_path:
label_name = os.path.join(path, image_path)
img = nib.load(label_name)
data = img.get_fdata()
n=0;
u=0;
m=0;
b=0;
e=0;
r=0;
s=0;
img1=img
data1 = img1.get_fdata()
for i in range (0,img.shape[0]):
for j in range (0,img.shape[1]):
for k in range (0,img.shape[2]):
if data[i,j,k]==500:
n=n+1;
data1[i,j,k]=1;
elif data[i,j,k]==600:
u=u+1;
data1[i,j,k]=2;
elif data[i,j,k]==420:
b=b+1;
data1[i,j,k]=3;
elif data[i,j,k]==550:
e=e+1;
data1[i,j,k]=4;
elif data[i,j,k]==205:
r=r+1;
data1[i,j,k]=5;
elif data[i,j,k]==820:
m=m+1;
data1[i,j,k]=6;
elif data[i,j,k]==850:
s=s+1;
data1[i,j,k]=7
OUTPUT_DIR='/Volumes/CSE_BME_AXM788/home/gxa131/labelsTr_new/'
dir1=os.path.join(OUTPUT_DIR, image_path)
sitk.WriteImage(data1,dir1)