I have a zip-file that contains .nrrd type files. The pynrrd lib comes with a read function. How can I pull the .nrrd
file from the zip and pass it to the nrrd.read()
function?
I tried following, but that gives the following error at the nrrd.read()
line:
TypeError was unhandled by user code, file() argument 1 must be encoded string without NULL bytes, not str
in_dir = r'D:\Temp\Slikvideo\JPEG\SV_4_1_mask'
zip_file = 'Annotated.mitk'
zf = zipfile.ZipFile(in_dir + '\\' + zip_file)
f_name = 'datafile.nrrd' # .nrrd file in zip
file_nrrd = zf.read(f_name) # pull the file from the zip
img_nrrd, options = nrrd.read(file_nrrd) # read the .nrrd image data from the file
I could write the file pulled from the .zip to disk, and then read it from disk with nrrd.read()
but I am sure there is a better way.