本文整理汇总了Python中msct_image.Image.argmax方法的典型用法代码示例。如果您正苦于以下问题:Python Image.argmax方法的具体用法?Python Image.argmax怎么用?Python Image.argmax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msct_image.Image
的用法示例。
在下文中一共展示了Image.argmax方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_centerline_from_point
# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import argmax [as 别名]
def get_centerline_from_point(input_image, point_file, gap=4, gaussian_kernel=4, remove_tmp_files=1):
# Initialization
fname_anat = input_image
fname_point = point_file
slice_gap = gap
remove_tmp_files = remove_tmp_files
gaussian_kernel = gaussian_kernel
start_time = time()
verbose = 1
# get path of the toolbox
status, path_sct = commands.getstatusoutput("echo $SCT_DIR")
path_sct = sct.slash_at_the_end(path_sct, 1)
# Parameters for debug mode
if param.debug == 1:
sct.printv("\n*** WARNING: DEBUG MODE ON ***\n\t\t\tCurrent working directory: " + os.getcwd(), "warning")
status, path_sct_testing_data = commands.getstatusoutput("echo $SCT_TESTING_DATA_DIR")
fname_anat = path_sct_testing_data + "/t2/t2.nii.gz"
fname_point = path_sct_testing_data + "/t2/t2_centerline_init.nii.gz"
slice_gap = 5
# check existence of input files
sct.check_file_exist(fname_anat)
sct.check_file_exist(fname_point)
# extract path/file/extension
path_anat, file_anat, ext_anat = sct.extract_fname(fname_anat)
path_point, file_point, ext_point = sct.extract_fname(fname_point)
# extract path of schedule file
# TODO: include schedule file in sct
# TODO: check existence of schedule file
file_schedule = path_sct + param.schedule_file
# Get input image orientation
input_image_orientation = get_orientation_3d(fname_anat, filename=True)
# Display arguments
print "\nCheck input arguments..."
print " Anatomical image: " + fname_anat
print " Orientation: " + input_image_orientation
print " Point in spinal cord: " + fname_point
print " Slice gap: " + str(slice_gap)
print " Gaussian kernel: " + str(gaussian_kernel)
print " Degree of polynomial: " + str(param.deg_poly)
# create temporary folder
print ("\nCreate temporary folder...")
path_tmp = "tmp." + strftime("%y%m%d%H%M%S")
sct.create_folder(path_tmp)
print "\nCopy input data..."
sct.run("cp " + fname_anat + " " + path_tmp + "/tmp.anat" + ext_anat)
sct.run("cp " + fname_point + " " + path_tmp + "/tmp.point" + ext_point)
# go to temporary folder
os.chdir(path_tmp)
# convert to nii
im_anat = convert("tmp.anat" + ext_anat, "tmp.anat.nii")
im_point = convert("tmp.point" + ext_point, "tmp.point.nii")
# Reorient input anatomical volume into RL PA IS orientation
print "\nReorient input volume to RL PA IS orientation..."
set_orientation(im_anat, "RPI")
im_anat.setFileName("tmp.anat_orient.nii")
# Reorient binary point into RL PA IS orientation
print "\nReorient binary point into RL PA IS orientation..."
# sct.run(sct.fsloutput + 'fslswapdim tmp.point RL PA IS tmp.point_orient')
set_orientation(im_point, "RPI")
im_point.setFileName("tmp.point_orient.nii")
# Get image dimensions
print "\nGet image dimensions..."
nx, ny, nz, nt, px, py, pz, pt = Image("tmp.anat_orient.nii").dim
print ".. matrix size: " + str(nx) + " x " + str(ny) + " x " + str(nz)
print ".. voxel size: " + str(px) + "mm x " + str(py) + "mm x " + str(pz) + "mm"
# Split input volume
print "\nSplit input volume..."
im_anat_split_list = split_data(im_anat, 2)
file_anat_split = []
for im in im_anat_split_list:
file_anat_split.append(im.absolutepath)
im.save()
im_point_split_list = split_data(im_point, 2)
file_point_split = []
for im in im_point_split_list:
file_point_split.append(im.absolutepath)
im.save()
# Extract coordinates of input point
data_point = Image("tmp.point_orient.nii").data
x_init, y_init, z_init = unravel_index(data_point.argmax(), data_point.shape)
sct.printv("Coordinates of input point: (" + str(x_init) + ", " + str(y_init) + ", " + str(z_init) + ")", verbose)
# Create 2D gaussian mask
sct.printv("\nCreate gaussian mask from point...", verbose)
#.........这里部分代码省略.........
示例2: main
# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import argmax [as 别名]
#.........这里部分代码省略.........
# go to temporary folder
os.chdir(path_tmp)
# convert to nii
convert('tmp.anat'+ext_anat, 'tmp.anat.nii')
convert('tmp.point'+ext_point, 'tmp.point.nii')
# Reorient input anatomical volume into RL PA IS orientation
print '\nReorient input volume to RL PA IS orientation...'
#sct.run(sct.fsloutput + 'fslswapdim tmp.anat RL PA IS tmp.anat_orient')
set_orientation('tmp.anat.nii', 'RPI', 'tmp.anat_orient.nii')
# Reorient binary point into RL PA IS orientation
print '\nReorient binary point into RL PA IS orientation...'
# sct.run(sct.fsloutput + 'fslswapdim tmp.point RL PA IS tmp.point_orient')
set_orientation('tmp.point.nii', 'RPI', 'tmp.point_orient.nii')
# Get image dimensions
print '\nGet image dimensions...'
nx, ny, nz, nt, px, py, pz, pt = Image('tmp.anat_orient.nii').dim
print '.. matrix size: '+str(nx)+' x '+str(ny)+' x '+str(nz)
print '.. voxel size: '+str(px)+'mm x '+str(py)+'mm x '+str(pz)+'mm'
# Split input volume
print '\nSplit input volume...'
split_data('tmp.anat_orient.nii', 2, '_z')
file_anat_split = ['tmp.anat_orient_z'+str(z).zfill(4) for z in range(0, nz, 1)]
split_data('tmp.point_orient.nii', 2, '_z')
file_point_split = ['tmp.point_orient_z'+str(z).zfill(4) for z in range(0, nz, 1)]
# Extract coordinates of input point
# sct.printv('\nExtract the slice corresponding to z='+str(z_init)+'...', verbose)
#
data_point = Image('tmp.point_orient.nii').data
x_init, y_init, z_init = unravel_index(data_point.argmax(), data_point.shape)
sct.printv('Coordinates of input point: ('+str(x_init)+', '+str(y_init)+', '+str(z_init)+')', verbose)
# Create 2D gaussian mask
sct.printv('\nCreate gaussian mask from point...', verbose)
xx, yy = mgrid[:nx, :ny]
mask2d = zeros((nx, ny))
radius = round(float(gaussian_kernel+1)/2) # add 1 because the radius includes the center.
sigma = float(radius)
mask2d = exp(-(((xx-x_init)**2)/(2*(sigma**2)) + ((yy-y_init)**2)/(2*(sigma**2))))
# Save mask to 2d file
file_mask_split = ['tmp.mask_orient_z'+str(z).zfill(4) for z in range(0,nz,1)]
nii_mask2d = Image('tmp.anat_orient_z0000.nii')
nii_mask2d.data = mask2d
nii_mask2d.setFileName(file_mask_split[z_init]+'.nii')
nii_mask2d.save()
#
# # Get the coordinates of the input point
# print '\nGet the coordinates of the input point...'
# data_point = Image('tmp.point_orient.nii').data
# x_init, y_init, z_init = unravel_index(data_point.argmax(), data_point.shape)
# print '('+str(x_init)+', '+str(y_init)+', '+str(z_init)+')'
# x_init, y_init, z_init = (data > 0).nonzero()
# x_init = x_init[0]
# y_init = y_init[0]
# z_init = z_init[0]
# print '('+str(x_init)+', '+str(y_init)+', '+str(z_init)+')'
#
# numpy.unravel_index(a.argmax(), a.shape)
#
# file = nibabel.load('tmp.point_orient.nii')