Operate on slices of 3D image in SimpleITK and create new 3D image

萝らか妹 提交于 2019-12-05 22:33:20

Use the Paste function to paste your slice image into the volume. The only slight trick is that the Paste function assumes both images are 3d. So you need to convert your 2d image into a 3d image (with z size of 1). You can do this with the JoinSeries function.

Here is an example python script to show how this would work

#! /usr/bin/env python

import SimpleITK as sitk

# make a black volume
vol_img = sitk.Image(100,100,100,sitk.sitkUInt8)

# make a white slice
slice_img = sitk.Image(100,100,sitk.sitkUInt8)
slice_img = slice_img + 200

# convert the 2d slice into a 3d volume
slice_vol = sitk.JoinSeries(slice_img)

# z insertion location
z = 42

# paste the 3d white slice into the black volume
pasted_img = sitk.Paste(vol_img, slice_vol, slice_vol.GetSize(), destinationIndex=[0,0,z])

sitk.Show(pasted_img)

I haven't experience with simpleITK, but it seems they provide a Paste method (example)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!