I am going to read a nifti image and change the values of the voxels and save the new nifti image similar to the main image but only different voxel values. In other words I want my labels in segmentation image be from 0 to 7 instead of having different numbers. o wrote the code below but I get this error:
NotImplementedError: Wrong number or type of arguments for overloaded function 'WriteImage'.
Possible C/C++ prototypes are: 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)
The code:
for image_path in os.listdir(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)