Ubuntu中python调用SimpleITK来显示图像

转自:http://blog.csdn.net/jiandanjinxin/article/details/53232440

misc.imshow

ipython
import os
from scipy import misc
dataDir = os.environ["HOME"] + "/Downloads/SimpleITK-MICCAI-2001-Tutorial-master/Data"
print dataDir
image = misc.imread(dataDir + "FA.png")
misc.imshow(image)

或者
ipython
import os
from scipy import misc
fileName ='/home/bids/Downloads/SimpleITK-MICCAI-2001-Tutorial-master/Data/FA.png'
print dataDir
image = misc.imread(fileName)
misc.imshow(image)

sitk.Show
ipython
import SimpleITK as sitk
fileName ='/home/bids/Downloads/SimpleITK-MICCAI-2001-Tutorial-master/Data/FA.png'
img = sitk.ReadImage(fileName)
scalarImage = sitk.Cast(img,sitk.sitkUInt32)
sitk.Show(scalarImage)

或者
ipython
import SimpleITK as sitk
import os
dataDir = os.environ["HOME"] + "/Downloads/SimpleITK-MICCAI-2001-Tutorial-master/Data"
print dataDir
image = sitk.ReadImage(dataDir + "/FA.png")
sitk.Show(image)

备注:
采用sitk.Show 是 默认打开imagej去打开图像,往往有时候仅仅是打开了imagej,而无法显示图像。

References

http://stackoverflow.com/questions/34726455/setting-the-image-viewer-in-python



这部分内容未测试,具体情况不明:

import itk
pixelType = itk.UC
imageType = itk.Image[pixelType, 2]
readerType = itk.ImageFileReader[imageType]
writerType = itk.ImageFileWriter[imageType]
reader = readerType.New()
writer = writerType.New()
reader.SetFileName("")
writer.SetFileName("D:/Output.png")
writer.SetInput( reader.GetOutput() )
writer.Update()


你可能感兴趣的:(Python)