Write file


In [1]:
%pylab inline
import io3d
import numpy as np
import matplotlib.pyplot as plt

data3d = (np.random.random([6, 100, 120]) * 30).astype(np.int16)
data3d[0:4, 20:60, 60:70] += 60
metadata = {'voxelsize_mm': [0.5, 0.5, 4]}


import sed3
plt.figure(figsize=(10,5))
sed3.show_slices(data3d)


Populating the interactive namespace from numpy and matplotlib

Write file in dicom format


In [2]:
io3d.write(data3d=data3d.astype("uint16"), path="~/data/temp0/singlefile.dcm")

Write file-stack in .jpg format


In [3]:
io3d.write(data3d=data3d.astype("uint8"), path="~/data/temp1/image_{:04d}.jpg")

Write file-stack in .dcm format with voxel size definition


In [6]:
io3d.write(data3d=data3d.astype("uint16"), path="~/data/temp2/image_{:04d}.dcm", metadata={"voxelsize_mm": [1., 5., .5]})