本文整理汇总了Python中SimpleITK.BSplineTransformInitializer方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleITK.BSplineTransformInitializer方法的具体用法?Python SimpleITK.BSplineTransformInitializer怎么用?Python SimpleITK.BSplineTransformInitializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleITK
的用法示例。
在下文中一共展示了SimpleITK.BSplineTransformInitializer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: produceRandomlyDeformedImage
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import BSplineTransformInitializer [as 别名]
def produceRandomlyDeformedImage(image, label, numcontrolpoints, stdDef):
sitkImage=sitk.GetImageFromArray(image, isVector=False)
sitklabel=sitk.GetImageFromArray(label, isVector=False)
transfromDomainMeshSize=[numcontrolpoints]*sitkImage.GetDimension()
tx = sitk.BSplineTransformInitializer(sitkImage,transfromDomainMeshSize)
params = tx.GetParameters()
paramsNp=np.asarray(params,dtype=float)
paramsNp = paramsNp + np.random.randn(paramsNp.shape[0])*stdDef
paramsNp[0:int(len(params)/3)]=0 #remove z deformations! The resolution in z is too bad
params=tuple(paramsNp)
tx.SetParameters(params)
resampler = sitk.ResampleImageFilter()
resampler.SetReferenceImage(sitkImage)
resampler.SetInterpolator(sitk.sitkLinear)
resampler.SetDefaultPixelValue(0)
resampler.SetTransform(tx)
resampler.SetDefaultPixelValue(0)
outimgsitk = resampler.Execute(sitkImage)
outlabsitk = resampler.Execute(sitklabel)
outimg = sitk.GetArrayFromImage(outimgsitk)
outimg = outimg.astype(dtype=np.float32)
outlbl = sitk.GetArrayFromImage(outlabsitk)
outlbl = (outlbl>0.5).astype(dtype=np.float32)
return outimg,outlbl
示例2: get_bspline_transform
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import BSplineTransformInitializer [as 别名]
def get_bspline_transform(
image: sitk.Image,
num_control_points: Tuple[int, int, int],
coarse_field: np.ndarray,
) -> sitk.BSplineTransformInitializer:
mesh_shape = [n - SPLINE_ORDER for n in num_control_points]
bspline_transform = sitk.BSplineTransformInitializer(image, mesh_shape)
parameters = coarse_field.flatten(order='F').tolist()
bspline_transform.SetParameters(parameters)
return bspline_transform
示例3: gen_warp_field
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import BSplineTransformInitializer [as 别名]
def gen_warp_field(shape, sigma=0.1, grid_size=3):
'''Generate an spline warp field'''
import SimpleITK as sitk
# Initialize bspline transform
args = shape+(sitk.sitkFloat32,)
ref_image = sitk.Image(*args)
tx = sitk.BSplineTransformInitializer(ref_image, [grid_size, grid_size])
# Initialize shift in control points:
# mesh size = number of control points - spline order
p = sigma * np.random.randn(grid_size+3, grid_size+3, 2)
# Anchor the edges of the image
p[:, 0, :] = 0
p[:, -1:, :] = 0
p[0, :, :] = 0
p[-1:, :, :] = 0
# Set bspline transform parameters to the above shifts
tx.SetParameters(p.flatten())
# Compute deformation field
displacement_filter = sitk.TransformToDisplacementFieldFilter()
displacement_filter.SetReferenceImage(ref_image)
displacement_field = displacement_filter.Execute(tx)
return displacement_field
示例4: produceRandomlyDeformedImage
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import BSplineTransformInitializer [as 别名]
def produceRandomlyDeformedImage(image, label, numcontrolpoints, stdDef, seed=1):
'''
This function comes from V-net,deform a image by B-spine interpolation
:param image: images ,numpy array
:param label: labels,numpy array
:param numcontrolpoints: control point,B-spine interpolation parameters,take 2 for default
:param stdDef: Deviation,B-spine interpolation parameters,take 15 for default
:return: Deformed images and GT in numpy array
'''
sitkImage = sitk.GetImageFromArray(image, isVector=False)
sitklabel = sitk.GetImageFromArray(label, isVector=False)
transfromDomainMeshSize = [numcontrolpoints] * sitkImage.GetDimension()
tx = sitk.BSplineTransformInitializer(
sitkImage, transfromDomainMeshSize)
params = tx.GetParameters()
paramsNp = np.asarray(params, dtype=float)
# 设置种子值,确保多通道时两个通道变换程度一样
np.random.seed(seed)
paramsNp = paramsNp + np.random.randn(paramsNp.shape[0]) * stdDef
# remove z deformations! The resolution in z is too bad
paramsNp[0:int(len(params) / 3)] = 0
params = tuple(paramsNp)
tx.SetParameters(params)
resampler = sitk.ResampleImageFilter()
resampler.SetReferenceImage(sitkImage)
resampler.SetInterpolator(sitk.sitkLinear)
resampler.SetDefaultPixelValue(0)
resampler.SetTransform(tx)
resampler.SetDefaultPixelValue(0)
outimgsitk = resampler.Execute(sitkImage)
outlabsitk = resampler.Execute(sitklabel)
outimg = sitk.GetArrayFromImage(outimgsitk)
outimg = outimg.astype(dtype=np.float32)
outlbl = sitk.GetArrayFromImage(outlabsitk)
# outlbl = (outlbl > 0.5).astype(dtype=np.float32)
return outimg, outlbl
示例5: produceRandomlyDeformedImage
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import BSplineTransformInitializer [as 别名]
def produceRandomlyDeformedImage(image, label, numcontrolpoints=2, stdDef=15):
sitkImage=sitk.GetImageFromArray(image, isVector=False)
sitklabel=sitk.GetImageFromArray(label, isVector=False)
transfromDomainMeshSize=[numcontrolpoints]*sitkImage.GetDimension()
tx = sitk.BSplineTransformInitializer(sitkImage,transfromDomainMeshSize)
params = tx.GetParameters()
paramsNp=np.asarray(params,dtype=float)
paramsNp = paramsNp + np.random.randn(paramsNp.shape[0])*stdDef
#remove z deformations! The resolution in z is too bad in case of 3D or its channels in 2D
paramsNp[0:int(len(params)/3)]=0 #remove z deformations! The resolution in z is too bad in case of 3D or its channels
params=tuple(paramsNp)
tx.SetParameters(params)
# print (sitkImage.GetSize(), sitklabel.GetSize(), transfromDomainMeshSize, paramsNp.shape)
resampler = sitk.ResampleImageFilter()
resampler.SetReferenceImage(sitkImage)
resampler.SetInterpolator(sitk.sitkLinear)
resampler.SetDefaultPixelValue(0)
resampler.SetTransform(tx)
outimgsitk = resampler.Execute(sitkImage)
# For Label use nearest neighbour
resampler.SetReferenceImage(sitklabel)
resampler.SetInterpolator(sitk.sitkLabelGaussian)
resampler.SetDefaultPixelValue(0)
outlabsitk = resampler.Execute(sitklabel)
outimg = sitk.GetArrayFromImage(outimgsitk)
outimg = outimg.astype(dtype=np.float32)
outlbl = sitk.GetArrayFromImage(outlabsitk)
outlbl = (outlbl).astype(dtype=np.uint8)
return outimg, outlbl
# ********************************Augmentation Transforms**************************#
开发者ID:mahendrakhened,项目名称:Automated-Cardiac-Segmentation-and-Disease-Diagnosis,代码行数:44,代码来源:data_augmentation.py