本文整理汇总了Python中msct_image.Image.hdr['pixdim']方法的典型用法代码示例。如果您正苦于以下问题:Python Image.hdr['pixdim']方法的具体用法?Python Image.hdr['pixdim']怎么用?Python Image.hdr['pixdim']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msct_image.Image
的用法示例。
在下文中一共展示了Image.hdr['pixdim']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: concat_data
# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import hdr['pixdim'] [as 别名]
def concat_data(fname_in_list, dim, pixdim=None):
"""
Concatenate data
:param im_in_list: list of images.
:param dim: dimension: 0, 1, 2, 3.
:param pixdim: pixel resolution to join to image header
:return im_out: concatenated image
"""
# WARNING: calling concat_data in python instead of in command line causes a non understood issue (results are different with both options)
from numpy import concatenate, expand_dims, squeeze
dat_list = []
data_concat_list = []
# check if shape of first image is smaller than asked dim to concatenate along
data0 = Image(fname_in_list[0]).data
if len(data0.shape) <= dim:
expand_dim = True
else:
expand_dim = False
for i, fname in enumerate(fname_in_list):
# if there is more than 100 images to concatenate, then it does it iteratively to avoid memory issue.
if i != 0 and i % 100 == 0:
data_concat_list.append(concatenate(dat_list, axis=dim))
im = Image(fname)
dat = im.data
if expand_dim:
dat = expand_dims(dat, dim)
dat_list = [dat]
del im
del dat
else:
im = Image(fname)
dat = im.data
if expand_dim:
dat = expand_dims(dat, dim)
dat_list.append(dat)
del im
del dat
if data_concat_list:
data_concat_list.append(concatenate(dat_list, axis=dim))
data_concat = concatenate(data_concat_list, axis=dim)
else:
data_concat = concatenate(dat_list, axis=dim)
# write file
im_out = Image(fname_in_list[0]).copy()
im_out.data = data_concat
im_out.setFileName(im_out.file_name+'_concat'+im_out.ext)
if pixdim is not None:
im_out.hdr['pixdim'] = pixdim
return im_out