本文整理汇总了Python中Image.Image.write_decomposition方法的典型用法代码示例。如果您正苦于以下问题:Python Image.write_decomposition方法的具体用法?Python Image.write_decomposition怎么用?Python Image.write_decomposition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image.Image
的用法示例。
在下文中一共展示了Image.write_decomposition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: len
# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import write_decomposition [as 别名]
import numpy as np
from Image import Image
from sklearn.decomposition import PCA
import scipy.io as sio
import nibabel as nib
import os.path
parser = argparse.ArgumentParser(description='fMRI analysis pipeline for matrix decomposition')
parser.add_argument('-img', metavar='image', type=str, nargs='+', required=True)
parser.add_argument('-mask', metavar='mask', type=str, nargs='+', required=True)
parser.add_argument('-n', metavar='n_components', type=int, required=True)
parser.add_argument('-fwhm', metavar='fwhm', type=int, required=True)
args = parser.parse_args()
if len(args.img)!=len(args.mask):
print "ERROR: length of image and mask list is not equal ... exit"
sys.exit()
for index, scan in enumerate(args.img):
print scan+" "+args.mask[index]
img = Image(img_filename=scan, mask_filename=args.mask[index], fwhm=args.fwhm)
mat = img.image_mat_in_mask_normalised
pca = PCA(n_components=args.n, whiten=True)
mat_reduced = pca.fit_transform(mat)
#print "Variance explained "+str(pca.explained_variance_ratio_)
f = open((scan[0:scan.find('.nii')]+'.pca.txt'),'w')
f.write(str(pca.explained_variance_ratio_))
f.close()
img.write_decomposition(maps=mat_reduced.T,filename=(scan[0:scan.find('.nii')]+'.pca_reduced.nii.gz'),normalise=False)
#import pdb; pdb.set_trace()
示例2: xrange
# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import write_decomposition [as 别名]
control_vs_ad_t = np.zeros((53795,30))
control_vs_ad_p = np.zeros((53795,30))
for i in xrange(53795):
for c in xrange(30):
t, p = ttest_ind(group_sum[i,all_labels==1,c], group_sum[i,all_labels==3,c], equal_var=False)
control_vs_ad_t[i,c] = t
control_vs_ad_p[i,c] = p
# alpha = 0.05
# for c in xrange(30):
# t_bool, pcorr = tools.fdr(control_vs_ad_p[:,c].ravel(),alpha=alpha)
# control_vs_ad_t[t_bool==False,c]=0
# control_vs_ad_p[:,c] = pcorr
decomp.write_decomposition(maps=control_vs_ad_t.T, filename='_ica_control_vs_ad_ttest.nii.gz', normalise=False)
decomp.write_decomposition(maps=control_vs_ad_p.T, filename='_ica_control_vs_ad_ttest_p.nii.gz', normalise=False)
else:
########################################################################################################################
########################################################################################################################
######################################## COMPUTE INDIVIDUAL AND GROUP DECOMPOSITION ####################################
########################################################################################################################
########################################################################################################################
all_labels = np.zeros((len(args.autoencoder)))
all_decompositions = np.zeros((len(args.autoencoder),98,30))
for index, scan in enumerate(args.autoencoder):
print "Using scan: "+scan+" with atlas: "+args.atlas[index]
first_point_index = scan.find('.')
last_slash_index = scan.rfind('/')
示例3: enumerate
# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import write_decomposition [as 别名]
# for weight_idx,weight in enumerate([0.5,0.1,0.05,0.01,0.001]):
# filename = (scan[0:scan.find('.nii')]+'.fwhm'+str(args.fwhm)+'mm.'+'_backpropagation_groupbias.'+d[weight]+'.nii.gz')
# print filename
# ae_voxels_restricted=Autoencoder(img.image_mat_in_mask_normalised.shape[1], max_iter=args.maxiter, weight_decay_param=weight).fit(img.image_mat_in_mask_normalised.T, params_init_scan, params_bias_scan)
# img.write_decomposition(maps=ae_voxels_restricted.components_,filename=filename,normalise=False)
# #with open((filename[0:filename.find('.nii')]+'.evs.txt'), 'w') as f:
# # f.write('%f' % evs(img.image_mat_in_mask_normalised.T.ravel(), ae_voxels_restricted.x_mat_tilde.ravel()))
#
# stats[index,weight_idx]=evs(img.image_mat_in_mask_normalised.T.ravel(), ae_voxels_restricted.x_mat_tilde.ravel())
# print "error: "+str(evs(img.image_mat_in_mask_normalised.T.ravel(), ae_voxels_restricted.x_mat_tilde.ravel()))
# ... and without
filename = (scan[0:scan.find('.nii')]+'.fwhm'+str(args.fwhm)+'mm.'+'_backpropagation_groupbias_rica.reference.nii.gz')
rica=RICA(img.image_mat_in_mask_normalised.shape[1], max_iter=args.maxiter, weight_decay_param=args.weight_decay).fit(img.image_mat_in_mask_normalised.T, params_init_scan_rica, optimization=False)
img.write_decomposition(maps=rica.components_, filename=filename, normalise=True)
filename = (scan[0:scan.find('.nii')]+'.fwhm'+str(args.fwhm)+'mm.'+'_backpropagation_groupbias_rica.'+str(args.weight_decay)+'.nii.gz')
rica=RICA(img.image_mat_in_mask_normalised.shape[1], max_iter=args.maxiter, weight_decay_param=args.weight_decay).fit(img.image_mat_in_mask_normalised.T, params_init_scan_rica, params_bias_scan_rica, optimization=True)
img.write_decomposition(maps=rica.components_, filename=filename, normalise=True)
W_all_new[:, i:j] = rica.W
filename = (scan[0:scan.find('.nii')]+'.fwhm'+str(args.fwhm)+'mm.'+'_backpropagation_groupbias.reference.nii.gz')
ae_voxels=Autoencoder(img.image_mat_in_mask_normalised.shape[1], max_iter=args.maxiter, weight_decay_param=args.weight_decay, second_nonlinear=True).fit(img.image_mat_in_mask_normalised.T, params_init_scan, optimization=False)
img.write_decomposition(maps=ae_voxels.components_,filename=filename, normalise=False)
filename = (scan[0:scan.find('.nii')]+'.fwhm'+str(args.fwhm)+'mm.'+'_backpropagation_groupbias.'+str(args.weight_decay)+'.nii.gz')
ae_voxels=Autoencoder(img.image_mat_in_mask_normalised.shape[1], max_iter=args.maxiter, weight_decay_param=args.weight_decay, second_nonlinear=True).fit(img.image_mat_in_mask_normalised.T, params_init_scan, params_bias_scan, optimization=True)
img.write_decomposition(maps=ae_voxels.components_,filename=filename, normalise=False)
break