In [1]:
%matplotlib inline

Basic Input/Output

This tutorial covers basic input and output operations supported by ndreg. Images can be obtaind by either downloading them or reading them from a file. Likewise they can be saved by either uploading them or writing to a disk. Although ndreg does not support image visualization, we can easily view images using matplotlib


In [2]:
import SimpleITK as sitk
import matplotlib.pyplot as plt
from ndreg import *

Downloading an image

An entire image volume can be downloaded using imgDownload. Since only project token "checkerBig" is provided, it will download the default channel of the project at it's highest resolution


In [3]:
myImg = imgDownload("checkerBig")

The downoladed image is stored as SimpleITK image


In [4]:
type(myImg)


Out[4]:
SimpleITK.SimpleITK.Image

Visualizing an image

SimpleITK images can easilly be converted to numpy arrays for visualization


In [5]:
plt.imshow(sitk.GetArrayFromImage(myImg), cmap=plt.cm.gray)
plt.show()


To save some keyboard strokes ndreg's imgShow can also be used


In [6]:
imgShow(myImg)


Writing an image to file

We can write the downloaded image to a file using the imgWrite method. Since imgWrite is an alias of SimpleITK.writeImage it supports all file formats that ITK supports.


In [ ]:
imgWrite(myImg, "myImg.png")

Reading an image

Images can be read from a file using the imgRead method. Like imgWrite, imgRead can read any file format that ITK can read.


In [ ]:
myImg2 = imgRead("myImg.png")

Uploading an image

Finally images can be uploaded to a project specified by "myToken" using imgUpload. The following uploads an myImg2 to the default channel's highest resolution.


In [ ]:
imgUpload(myImg2, "myToken")