本文整理汇总了Python中surfer.Brain.save_image方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.save_image方法的具体用法?Python Brain.save_image怎么用?Python Brain.save_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类surfer.Brain
的用法示例。
在下文中一共展示了Brain.save_image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawROI
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def drawROI():
for hemi in ["lh"]:
# load data
roivol = io.project_volume_data(roifile,
hemi,
subject_id=surfsubj,
smooth_fwhm=4.0,
projmeth="dist",
projsum="avg",
projarg=[0,6,0.1],
surf="white")
# create label
roivol = abs(roivol)
roivol[roivol < 0.33] = 0
#if max(roivol) < 1:
# brain.close()
# continue
#else:
write_label(np.asarray(np.nonzero(roivol)),"/gablab/p/bps/zqi_ytang/scripts/roi/surf-IFG.label")
# load brain
my_fig = mlab.figure(figure="new_fig1", size=(800,800))
brain = Brain("fsaverage",hemi,"inflated",curv=True,size=[800,800],background="white",cortex=(("gist_yarg",-1.5,3.5,False)),figure=my_fig)
set_mylights(my_fig,lights[hemi])
#add label
brain.add_label("/gablab/p/bps/zqi_ytang/scripts/roi/surf-IFG.label",borders=False,color="#ffff00",alpha=1)
brain.add_label("/gablab/p/bps/zqi_ytang/scripts/roi/surf-IFG.label",borders=1,color="black",alpha=0.5)
brain.show_view('lat')
brain.save_image("/gablab/p/bps/zqi_ytang/scripts/roi/surf-IFG.tiff")
brain.close()
示例2: curvature_normalization
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def curvature_normalization(data_dir, subj, close=True):
"""Normalize the curvature map and plot contour over fsaverage."""
surf_dir = op.join(data_dir, subj, "surf")
snap_dir = op.join(data_dir, subj, "snapshots")
for hemi in ["lh", "rh"]:
cmd = ["mri_surf2surf",
"--srcsubject", subj,
"--trgsubject", "fsaverage",
"--hemi", hemi,
"--sval", op.join(surf_dir, "%s.curv" % hemi),
"--tval", op.join(surf_dir, "%s.curv.fsaverage.mgz" % hemi)]
sub.check_output(cmd)
b = Brain("fsaverage", hemi, "inflated",
config_opts=dict(background="white",
width=700, height=500))
curv = nib.load(op.join(surf_dir, "%s.curv.fsaverage.mgz" % hemi))
curv = (curv.get_data() > 0).squeeze()
b.add_contour_overlay(curv, min=0, max=1.5, n_contours=2, line_width=4)
b.contour["colorbar"].visible = False
for view in ["lat", "med"]:
b.show_view(view)
mlab.view(distance=330)
png = op.join(snap_dir, "%s.surf_warp_%s.png" % (hemi, view))
b.save_image(png)
if close:
b.close()
示例3: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def test_image():
"""Test image saving
"""
mlab.options.backend = 'auto'
brain = Brain(*std_args, config_opts=small_brain)
tmp_name = mktemp() + '.png'
brain.save_image(tmp_name)
brain.save_imageset(tmp_name, ['med', 'lat'], 'jpg')
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='v')
brain.screenshot()
示例4: pysurfer_plot_perm_ttest_results
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def pysurfer_plot_perm_ttest_results(vertices, vertives_values, max_vals, fol):
T = max(vertices.keys())
for t in range(T+1):
print(t)
brain = Brain('fsaverage', 'split', 'pial', curv=False, offscreen=False, views=['lat', 'med'], title='{} ms'.format(t))
for hemi in ['rh', 'lh']:
if t in vertices:
brain.add_data(np.array(vertives_values[t][hemi]), hemi=hemi, min=1, max=max_vals, remove_existing=True,
colormap="YlOrRd", alpha=1, vertices=np.array(vertices[t][hemi]))
brain.save_image(os.path.join(fol, '{}.jpg'.format(t)))
brain.close()
示例5: inflated_surfaces
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def inflated_surfaces(out_dir, subj, close=True):
"""Native inflated surfaces with cortical label."""
for hemi in ["lh", "rh"]:
b = Brain(subj, hemi, "inflated", curv=False,
config_opts=dict(background="white",
width=800, height=500))
b.add_label("cortex", color="#6B6B6B")
for view in ["lat", "med"]:
b.show_view(view)
mlab.view(distance=400)
png = op.join(out_dir, "%s.surface_%s.png" % (hemi, view))
b.save_image(png)
if close:
b.close()
示例6: make_pysurfer_images
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def make_pysurfer_images(folder,suffix='cope1',threshold=0.9499,coords=(),surface='inflated',fwhm=0,filename='',saveFolder=[]):
from surfer import Brain, io
TFCEposImg,posImg,TFCEnegImg,negImg=getFileNamesfromFolder(folder,suffix)
pos=image.math_img("np.multiply(img1,img2)",
img1=image.threshold_img(TFCEposImg,threshold=threshold),img2=posImg)
neg=image.math_img("np.multiply(img1,img2)",
img1=image.threshold_img(TFCEnegImg,threshold=threshold),img2=negImg)
fw=image.math_img("img1-img2",img1=pos,img2=neg)
if fwhm==0:
smin=np.min(np.abs(fw.get_data()[fw.get_data()!=0]))
else:
smin=2
mri_file = "%s/thresholded_posneg.nii.gz" % folder
fw.to_filename(mri_file)
"""Bring up the visualization"""
brain = Brain("fsaverage", "split", surface ,views=['lat', 'med'], offscreen=True , background="white")
"""Project the volume file and return as an array"""
reg_file = os.path.join("/opt/freesurfer","average/mni152.register.dat")
surf_data_lh = io.project_volume_data(mri_file, "lh", reg_file,smooth_fwhm=fwhm)
surf_data_rh = io.project_volume_data(mri_file, "rh", reg_file,smooth_fwhm=fwhm)
"""
You can pass this array to the add_overlay method for a typical activation
overlay (with thresholding, etc.).
"""
brain.add_overlay(surf_data_lh, min=smin, max=5, name="ang_corr_lh", hemi='lh')
brain.add_overlay(surf_data_rh, min=smin, max=5, name="ang_corr_rh", hemi='rh')
if len(coords)>0:
if coords[0]>0:
hemi='rh'
else:
hemi='lh'
brain.add_foci(coords, map_surface="pial", color="gold",hemi=hemi)
if len(saveFolder)>0:
folder=saveFolder
brain.save_image('%s/%s.png' % (folder,filename))
else:
brain.save_image('%s/surfaceplot.jpg' % folder)
brain.close()
示例7: plot_data_surf_bh
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def plot_data_surf_bh(in_file, colormap='jet', thr_list=[(None, None, None)],roi_coords=(), fwhm=0):
'''
allows more flexible visualization than plot_rs_surf_bh
thr_list = [(min, max, thresh)]
colormap: matplotlib colormap (http://matplotlib.org/examples/color/colormaps_reference.html)
'''
# in_file .nii to be projected on surface
import os
from surfer import Brain, io
out_file_list = []
in_file_name = os.path.basename(in_file)
reg_file = os.path.join(os.environ["FREESURFER_HOME"],"average/mni152.register.dat")
for thr in thr_list:
min_thr = thr[0]
max_thr = thr[1]
thr_thr = thr[2]
brain = Brain("fsaverage", "split", "inflated", views=['lat', 'med'], config_opts=dict(background="white"))
surf_data_lh = io.project_volume_data(in_file, "lh", reg_file, smooth_fwhm=fwhm)
surf_data_rh = io.project_volume_data(in_file, "rh", reg_file, smooth_fwhm=fwhm)
brain.add_data(surf_data_lh, min=min_thr, max=max_thr, thresh=thr_thr, colormap=colormap, hemi='lh')
brain.add_data(surf_data_rh, min=min_thr, max=max_thr, thresh=thr_thr, colormap=colormap, hemi='rh')
roi_str = ''
if not(roi_coords == ()):
if roi_coords[0] <0: #lh
hemi_str = 'lh'
else:
hemi_str = 'rh'
roi_str = '_roi_%s.%s.%s' % roi_coords
brain.add_foci(roi_coords, map_surface="white", hemi=hemi_str, color='red', scale_factor=2)
out_filename = os.path.join(os.getcwd(), in_file_name + roi_str + '_thr_%s' % min_thr + '.png')
out_file_list += [out_filename]
brain.save_image(out_filename)
brain.close()
return out_file_list
示例8: plot_rs_surf
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def plot_rs_surf(in_file, thr_list=[(.2,1)],roi_coords=(), fwhm=0):
# in_file .nii to be projected on surface
# list of tuples defining min and max thr_list=[(.2,1)]
import os
import subprocess
from surfer import Brain, io
arch = subprocess.check_output('arch')
if arch.startswith('x86_'): # set offscrene rendering to avoid intereference on linux
from mayavi import mlab
mlab.options.offscreen = True
out_file_list = []
in_file_name = os.path.basename(in_file)
reg_file = os.path.join(os.environ["FREESURFER_HOME"],"average/mni152.register.dat")
for thr in thr_list:
min_thr = thr[0]
max_thr = thr[1]
print(min_thr)
print(max_thr)
for hemi in ['lh', 'rh']:
brain = Brain("fsaverage", hemi, "inflated", views=['lat', 'med'], config_opts=dict(background="white"))
surf_data = io.project_volume_data(in_file, hemi, reg_file, smooth_fwhm=fwhm)
brain.add_overlay(surf_data, min=min_thr, max=max_thr, name="ang_corr", hemi=hemi)
roi_str = ''
if not(roi_coords == ()):
if roi_coords[0] <0: #lh
hemi_str = 'lh'
else:
hemi_str = 'rh'
roi_str = '_roi_%s.%s.%s' % roi_coords
if hemi_str == hemi:
brain.add_foci(roi_coords, map_surface="white", hemi=hemi_str, color='red', scale_factor=2)
out_filename = os.path.join(os.getcwd(), in_file_name + roi_str + '_thr_%s' % min_thr + '_' + hemi + '.png')
out_file_list += [out_filename]
brain.save_image(out_filename)
brain.close()
return out_file_list
示例9: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def test_image():
"""Test image saving
"""
tmp_name = mktemp() + '.png'
mlab.options.backend = 'auto'
subject_id, _, surf = std_args
brain = Brain(subject_id, 'both', surf=surf, size=100)
brain.add_overlay(overlay_fname, hemi='lh', min=5, max=20, sign="pos")
brain.save_imageset(tmp_name, ['med', 'lat'], 'jpg')
brain = Brain(*std_args, size=100)
brain.save_image(tmp_name)
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='v')
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='h')
brain.save_montage(tmp_name, [['l', 'v'], ['m', 'f']])
brain.screenshot()
brain.close()
示例10: plot_rs_surf_bh
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def plot_rs_surf_bh(in_file, thr_list=[(.2,1)],roi_coords=(), fwhm=0):
# in_file .nii to be projected on surface
# list of tuples defining min and max thr_list=[(.2,1)]
import os
from surfer import Brain, io
out_file_list = []
in_file_name = os.path.basename(in_file)
reg_file = os.path.join(os.environ["FREESURFER_HOME"],"average/mni152.register.dat")
for thr in thr_list:
min_thr = thr[0]
max_thr = thr[1]
print(min_thr)
print(max_thr)
brain = Brain("fsaverage", "split", "inflated", views=['lat', 'med'], config_opts=dict(background="white"))
surf_data_lh = io.project_volume_data(in_file, "lh", reg_file, smooth_fwhm=fwhm)
surf_data_rh = io.project_volume_data(in_file, "rh", reg_file, smooth_fwhm=fwhm)
brain.add_overlay(surf_data_lh, min=min_thr, max=max_thr, name="ang_corr_lh", hemi='lh')
brain.add_overlay(surf_data_rh, min=min_thr, max=max_thr, name="ang_corr_rh", hemi='rh')
roi_str = ''
if not(roi_coords == ()):
if roi_coords[0] <0: #lh
hemi_str = 'lh'
else:
hemi_str = 'rh'
roi_str = '_roi_%s.%s.%s' % roi_coords
brain.add_foci(roi_coords, map_surface="white", hemi=hemi_str, color='red', scale_factor=2)
out_filename = os.path.join(os.getcwd(), in_file_name + roi_str + '_thr_%s' % min_thr + '.png')
out_file_list += [out_filename]
brain.save_image(out_filename)
brain.close()
return out_file_list
示例11: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def test_image(tmpdir):
"""Test image saving."""
tmp_name = tmpdir.join('temp.png')
tmp_name = str(tmp_name) # coerce to str to avoid PIL error
_set_backend()
subject_id, _, surf = std_args
brain = Brain(subject_id, 'both', surf=surf, size=100)
brain.add_overlay(overlay_fname, hemi='lh', min=5, max=20, sign="pos")
brain.save_imageset(tmp_name, ['med', 'lat'], 'jpg')
brain.close()
brain = Brain(*std_args, size=100)
brain.save_image(tmp_name)
brain.save_image(tmp_name, 'rgba', True)
brain.screenshot()
if os.getenv('TRAVIS', '') != 'true':
# for some reason these fail on Travis sometimes
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='v')
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='h')
brain.save_montage(tmp_name, [['l', 'v'], ['m', 'f']])
brain.close()
示例12: Brain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
from surfer import Brain
DST = '../images/brain_%s.png'
subjects_dir = '/Volumes/Seagate/refpred/mri'
surfaces = ('inflated',
'inflated_avg',
'inflated_pre',
# 'orig',
# 'pial',
'smoothwm',
'sphere',
'white')
for surf in surfaces:
brain = Brain('fsaverage', 'lh', surf, size=400, background='white',
subjects_dir=subjects_dir)
brain.save_image(DST % surf, 'rgba', True)
示例13:
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
label_fname = os.path.join(root, f)
label = mne.read_label(label_fname)
#label.values.fill(1.0)
#label_morph = label.morph(subject_from='fsaverage', subject_to=subject, smooth=5,
# n_jobs=1, copy=True)
if label.hemi == 'lh':
brain.add_label(label, color=random.choice(color))
elif label.hemi == 'rh':
brain.add_label(label, color=random.choice(color))
#brain.add_foci(vertno_max, coords_as_verts=True, hemi='lh', color='blue', scale_factor=0.6)
# If the label lives in the normal place in the subjects directory,
# you can plot it by just using the name
#ref_ROI_fname = '/home/qdong/freesurfer/subjects/fsaverage/label/lh.Auditory_82.label'
#ref_label = mne.read_label(ref_ROI_fname)
#brain.add_label(ref_label, color="blue")
#brain.add_label("ROI1", color="blue")
#brain.add_label("ROI2", color="red")
#brain.add_label("ROI3", color="green")
#brain.add_label("ROI4", color="blue")
#brain.add_label("ROI5", color="blue")
#brain.add_label("ROI6", color="blue")
#brain.add_label("ROI7", color="blue")
#brain.add_label("ROI8", color="blue")
#brain.add_label("ROI9", color="blue")
#brain.add_label("ROI10", color="blue")
#brain.add_label("ROI11", color="blue")
#brain.add_label("RefROI1", color="yellow")
#
brain.show_view("lateral")
brain.save_image('/home/qdong/freesurfer/subjects/101611/lh_ROI2.tiff')
示例14: drawContrast
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
def drawContrast(infile,outname):
for hemi in ["rh"]:
# load data
volpos = io.project_volume_data(infile,
hemi,
subject_id=surfsubj,
smooth_fwhm=4.0,
projmeth="dist",
projsum="max",
projarg=[-6,6,0.1],
surf="pial")
"""
volneg = io.project_volume_data(rsfcfile_neg,
hemi,
subject_id=surfsubj,
smooth_fwhm=4.0,
projmeth="dist",
projsum="max",
projarg=[-6,6,0.1],
surf="white")
volneg=volneg*-1
ccvol=volpos+volneg
"""
# load brain
my_fig = mlab.figure(figure="new_fig1", size=(800,800))
brain = Brain("fsaverage",hemi,"inflated",curv=True,size=[800,800],background="white",cortex=(("gist_yarg",-1.5,3.5,False)),figure=my_fig)
set_mylights(my_fig,lights[hemi])
if outname == "fig6b":
# create label
labIFG = volpos
labIFG[labIFG < 2.0739] = 0
write_label(np.asarray(np.nonzero(labIFG)),"fig6prep/roi_IFG.label")
#brain.add_label("fig6prep/roi_IFG.label",borders=False,color="red",alpha=0.125)
brain.add_label("fig6prep/roi_IFG.label",borders=2,color="#e7298a",alpha=1)
if outname == "fig6d":
# create label
labAG = io.project_volume_data("/gablab/p/CASL/Results/Imaging/resting/zqi/conn_CASL_pre_post_training13o/results/secondlevel/ANALYSIS_01/3mohsk_all(0).3mohsk(1)/pre-training(-1).post-training(1)/anat_func_lifg_1_1/roi_AG.nii.gz",
hemi,
subject_id=surfsubj,
smooth_fwhm=4.0,
projmeth="dist",
projsum="max",
projarg=[-6,6,0.1],
surf="pial")
labAG[labAG < 0.33] = 0
write_label(np.asarray(np.nonzero(labAG)),"fig6prep/roi_AG.label")
labSTGMTG = io.project_volume_data("/gablab/p/CASL/Results/Imaging/resting/zqi/conn_CASL_pre_post_training13o/results/secondlevel/ANALYSIS_01/3mohsk_all(0).3mohsk(1)/pre-training(-1).post-training(1)/anat_func_lifg_1_1/roi_STGMTG.nii.gz",
hemi,
subject_id=surfsubj,
smooth_fwhm=4.0,
projmeth="dist",
projsum="max",
projarg=[-6,6,0.1],
surf="pial")
labSTGMTG[labSTGMTG < 0.66] = 0
write_label(np.asarray(np.nonzero(labSTGMTG)),"fig6prep/roi_STGMTG.label")
#brain.add_label("fig6prep/roi_AG.label",borders=False,color="black",alpha=0.125)
brain.add_label("fig6prep/roi_AG.label",borders=2,color="#1b9e77",alpha=1)
#brain.add_label("fig6prep/roi_STGMTG.label",borders=False,color="blue",alpha=0.125)
brain.add_label("fig6prep/roi_STGMTG.label",borders=2,color="#7570b3",alpha=1)
brain.add_overlay(volpos,
min=2.0739, #p = 0.025 2-tailed
max=5.0216, #p = 0.000025, 2-tailed
sign="abs",
name=outname,
hemi=hemi)
brain.show_view('lat')
brain.save_image("fig6prep/%s.tiff"%(outname))
brain.close()
示例15:
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_image [as 别名]
rh_aparc_file = os.path.join(label_dir, right_label_file)
lh_labels, lh_ctab, lh_names = nb.freesurfer.read_annot(lh_aparc_file)
rh_labels, rh_ctab, rh_names = nb.freesurfer.read_annot(rh_aparc_file)
left_df = left_df.set_index('col').loc[lh_names].reset_index().fillna(0)
right_df = right_df.set_index('col').loc[rh_names].reset_index().fillna(0)
vtx_lh = left_df.val.values[lh_labels]
vtx_lh[lh_labels == -1] = 0
vtx_rh = right_df.val.values[rh_labels]
vtx_rh[rh_labels == -1] = 0
brain.add_data(vtx_lh,
0,
400,
colormap="Reds",
alpha=.8,
hemi='lh')
brain.add_annotation(lh_aparc_file, hemi='lh')
brain.add_data(vtx_rh,
0,
400,
colormap="Reds",
alpha=.8,
hemi='rh')
brain.add_annotation(rh_aparc_file, hemi='rh', remove_existing=False)
save_name = "../images/{}_brain.png".format(save_name)
brain.save_image(save_name)