本文整理匯總了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