This tutorial gives a brief introduction to medical image data analysis, visualization, and processing.
# load the required modules
import numpy as np
import SimpleITK as sitk
SimpleITK classes and functions have the Docstrings derived from the C++ definitions and the Doxygen documentation.
help(sitk.Image.GetPixel)
Help on method GetPixel in module SimpleITK.SimpleITK: GetPixel(self, *idx) unbound SimpleITK.SimpleITK.Image method Returns the value of a pixel. This method takes 2 parameters in 2D: the x and y index, and 3 parameters in 3D: the x, y and z index.
image = sitk.ReadImage('../sample_data/image.nii.gz')
imageSize = image.GetSize()
n_rows = imageSize[0]
n_cols = imageSize[1]
n_slices = imageSize[2]
print "(Image Size) number of rows:%d cols:%d slices:%d " % (imageSize[0],imageSize[1],imageSize[2])
(Image Size) number of rows:200 cols:225 slices:200
print image.GetOrigin()
print image.GetDirection()
(-99.5, -112.0, -99.5) (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
print image.GetSpacing()
(1.0, 1.0, 1.0)
print "The pixel value at x=50, y=50, z=50 is %d" % int(image.GetPixel(50, 50, 50))
image.SetPixel(50, 50, 50, 10)
print "The new value is %d" % int(image.GetPixel(50, 50, 50))
The pixel value at x=50, y=50, z=50 is 70 The new value is 10
print image[50,50,50]
10
stats = sitk.StatisticsImageFilter()
stats.Execute( image )
max = stats.GetMaximum()
min = stats.GetMinimum()
print 'Min intensity = {0} \nMax intensity = {1}'.format(min, max)
Min intensity = 0.0 Max intensity = 255.0
# Linearly rescale the intensity values
outputMinimum = 0
outputMaximum = 1024
rescaled_image = sitk.RescaleIntensity(image,outputMinimum,outputMaximum)
stats.Execute( rescaled_image )
max = stats.GetMaximum()
min = stats.GetMinimum()
print 'Min intensity = {0} \nMax intensity = {1}'.format(min, max)
Min intensity = 0.0 Max intensity = 1024.0