本文整理汇总了Python中msct_image.Image.data[ix,iy,iz]方法的典型用法代码示例。如果您正苦于以下问题:Python Image.data[ix,iy,iz]方法的具体用法?Python Image.data[ix,iy,iz]怎么用?Python Image.data[ix,iy,iz]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msct_image.Image
的用法示例。
在下文中一共展示了Image.data[ix,iy,iz]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_labeled_segmentation
# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import data[ix,iy,iz] [as 别名]
def clean_labeled_segmentation(fname_labeled_seg, fname_seg, fname_labeled_seg_new):
"""
Clean labeled segmentation by:
(i) removing voxels in segmentation_labeled that are not in segmentation and
(ii) adding voxels in segmentation that are not in segmentation_labeled
:param fname_labeled_seg:
:param fname_seg:
:param fname_labeled_seg_new: output
:return: none
"""
# remove voxels in segmentation_labeled that are not in segmentation
run('sct_maths -i '+fname_labeled_seg+' -mul '+fname_seg+' -o segmentation_labeled_mul.nii.gz')
# add voxels in segmentation that are not in segmentation_labeled
run('sct_maths -i '+fname_labeled_seg+' -dilate 2 -o segmentation_labeled_dilate.nii.gz') # dilate labeled segmentation
data_label_dilate = Image('segmentation_labeled_dilate.nii.gz').data
run('sct_maths -i segmentation_labeled_mul.nii.gz -bin 0 -o segmentation_labeled_mul_bin.nii.gz')
data_label_bin = Image('segmentation_labeled_mul_bin.nii.gz').data
data_seg = Image(fname_seg).data
data_diff = data_seg - data_label_bin
ind_nonzero = np.where(data_diff)
im_label = Image('segmentation_labeled_mul.nii.gz')
for i_vox in range(len(ind_nonzero[0])):
# assign closest label value for this voxel
ix, iy, iz = ind_nonzero[0][i_vox], ind_nonzero[1][i_vox], ind_nonzero[2][i_vox]
im_label.data[ix, iy, iz] = data_label_dilate[ix, iy, iz]
# save new label file (overwrite)
im_label.setFileName(fname_labeled_seg_new)
im_label.save()