I want to change the images in format .nii into .png but I get this error from the function imageio.imsave
:
ValueError: Max value == min value, ambiguous given dtype
Here is a part of the code:
import numpy, shutil, os, nibabel
import sys, getopt
import glob
import imageio
inputfile = 'lung_mask'
outputfile = 'lung_mask_png/'
if not os.path.exists(outputfile):
os.makedirs(outputfile)
for inputfile in glob.glob("lung_mask/*.nii"):
image_array = nibabel.load(inputfile).get_data()
nx, ny, nz = image_array.shape
total_slices = image_array.shape[2]
print(image_array.shape)
print(image_array.dtype)
data = numpy.rot90(image_array[:, :, 0])
image_name = inputfile[:-4] + ".png"
imageio.imsave(image_name, data.astype(numpy.int16))
shutil.move(image_name, outputfile)