本文整理汇总了Python中surfer.Brain.add_overlay方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.add_overlay方法的具体用法?Python Brain.add_overlay怎么用?Python Brain.add_overlay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类surfer.Brain
的用法示例。
在下文中一共展示了Brain.add_overlay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_overlay
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def test_overlay():
"""Test plotting of overlay
"""
mlab.options.backend = 'test'
# basic overlay support
overlay_file = pjoin(data_dir, "lh.sig.nii.gz")
brain = Brain(*std_args)
brain.add_overlay(overlay_file)
brain.overlays["sig"].remove()
brain.add_overlay(overlay_file, min=5, max=20, sign="pos")
sig1 = io.read_scalar_data(pjoin(data_dir, "lh.sig.nii.gz"))
sig2 = io.read_scalar_data(pjoin(data_dir, "lh.alt_sig.nii.gz"))
thresh = 4
sig1[sig1 < thresh] = 0
sig2[sig2 < thresh] = 0
conjunct = np.min(np.vstack((sig1, sig2)), axis=0)
brain.add_overlay(sig1, 4, 30, name="sig1")
brain.overlays["sig1"].pos_bar.lut_mode = "Reds"
brain.overlays["sig1"].pos_bar.visible = False
brain.add_overlay(sig2, 4, 30, name="sig2")
brain.overlays["sig2"].pos_bar.lut_mode = "Blues"
brain.overlays["sig2"].pos_bar.visible = False
brain.add_overlay(conjunct, 4, 30, name="conjunct")
brain.overlays["conjunct"].pos_bar.lut_mode = "Purples"
brain.overlays["conjunct"].pos_bar.visible = False
brain.close()
示例2: visMontage
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def visMontage(pathToSurface, overlay, outputPath, hemi, type='white'):
brain = Brain(pathToSurface, hemi, type)
brain.add_overlay(overlay, -5, 3)
brain.save_montage(outputPath, ['l', 'm'], orientation='v')
brain.close()
return outputPath
示例3: vizify
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def vizify(self):
for hemi in self.hemis:
print "visualize %s" % hemi
# Bring up the beauty (the underlay)
brain = Brain(self.subject_id, hemi, self.surf, \
config_opts=self.config_opts, \
subjects_dir=self.subjects_dir)
surf_data = io.read_scalar_data(self.overlay_surf[hemi])
if (sum(abs(surf_data)) > 0):
# Overlay another hopeful beauty (functional overlay)
brain.add_overlay(self.overlay_surf[hemi], name=self.overlay_name,
min=self.min, max=self.max, sign=self.sign)
# Update colorbar
#brain.overlays[self.overlay_name].pos_bar.lut_mode = self.colorbar
tmp = brain.overlays[self.overlay_name]
lut = tmp.pos_bar.lut.table.to_array()
lut[:,0:3] = self.colorbar
tmp.pos_bar.lut.table = lut
# Refresh
brain.show_view("lat")
brain.hide_colorbar()
# Save the beauts
brain.save_imageset("%s_%s" % (self.outprefix, hemi), self.views,
'jpg', colorbar=None)
# End a great journey, till another life
brain.close()
return
示例4: load_fmri
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def load_fmri(subject, input_file, hemi="both"):
brain = Brain(subject, hemi, "pial", curv=False)
brain.toggle_toolbars(True)
if hemi == "both":
for hemi in ["rh", "lh"]:
brain.add_overlay(input_file.format(hemi), hemi=hemi)
else:
brain.add_overlay(input_file.format(hemi), hemi=hemi)
示例5: main
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def main(subid, overlay):
_, fname = os.path.split(overlay)
hemi = fname[:2]
brain = Brain(subid, hemi, "pial",
config_opts=dict(cortex="low_contrast"))
brain.add_overlay(overlay, min=0.4, max=4, sign="pos")
brain.show_view('m')
示例6: corr_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def corr_image(resting_image,fwhm):
"""This function makes correlation image on brain surface"""
import numpy as np
import nibabel as nb
import matplotlib.pyplot as plt
from surfer import Brain, Surface
import os
img = nb.load(resting_image)
corrmat = np.corrcoef(np.squeeze(img.get_data()))
corrmat[np.isnan(corrmat)] = 0
corrmat_npz = os.path.abspath('corrmat.npz')
np.savez(corrmat_npz,corrmat=corrmat)
br = Brain('fsaverage5', 'lh', 'smoothwm')
#br.add_overlay(corrmat[0,:], min=0.2, name=0, visible=True)
lh_aparc_annot_file = os.path.join(os.environ["FREESURFER_HOME"],'/subjects/label/lh.aparc.annot')
values = nb.freesurfer.read_annot(lh_aparc_annot_file)
#br.add_overlay(np.mean(corrmat[values[0]==5,:], axis=0), min=0.8, name='mean', visible=True)
data = img.get_data()
data = np.squeeze(img.get_data())
#
precuneus_signal = np.mean(data[values[0]==np.nonzero(np.array(values[2])=='precuneus')[0][0],:], axis=0)
precuneus = np.corrcoef(precuneus_signal, data)
#precuneus.shape
#br.add_overlay(precuneus[0,1:], min=0.3, sign='pos', name='mean', visible=True)
br.add_overlay(precuneus[0,1:], min=0.2, name='mean')#, visible=True)
#br.add_overlay(precuneus[0,1:], min=0.2, name='mean')#, visible=True)
plt.hist(precuneus[0,1:], 128)
plt.savefig(os.path.abspath("histogram.png"))
plt.close()
corr_image = os.path.abspath("corr_image%s.png"%fwhm)
br.save_montage(corr_image)
ims = br.save_imageset(prefix=os.path.abspath('fwhm_%s'%str(fwhm)),views=['medial','lateral','caudal','rostral','dorsal','ventral'])
br.close()
print ims
#precuneus[np.isnan(precuneus)] = 0
#plt.hist(precuneus[0,1:])
roitable = [['Region','Mean Correlation']]
for i, roi in enumerate(np.unique(values[2])):
roitable.append([roi,np.mean(precuneus[values[0]==np.nonzero(np.array(values[2])==roi)[0][0]])])
#images = [corr_fimage]+ims+[os.path.abspath("histogram.png"), roitable]
roitable=[roitable]
histogram = os.path.abspath("histogram.png")
return corr_image, ims, roitable, histogram, corrmat_npz
示例7: make_brain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def make_brain(subject_id,image_path):
from surfer import Brain
hemi = 'lh'
surface = 'inflated'
brain = Brain(subject_id, hemi, surface)
brain.add_overlay(image_path,min=thr)
outpath = os.path.join(os.getcwd(),os.path.split(image_path)[1]+'_surf.png')
brain.save_montage(outpath)
return outpath
示例8: show_fMRI_using_pysurfer
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def show_fMRI_using_pysurfer(subject, input_file, hemi='both'):
brain = Brain(subject, hemi, "pial", curv=False, offscreen=False)
brain.toggle_toolbars(True)
if hemi=='both':
for hemi in ['rh', 'lh']:
print('adding {}'.format(input_file.format(hemi=hemi)))
brain.add_overlay(input_file.format(hemi=hemi), hemi=hemi)
else:
print('adding {}'.format(input_file.format(hemi=hemi)))
brain.add_overlay(input_file.format(hemi=hemi), hemi=hemi)
示例9: make_pysurfer_images_lh_rh
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def make_pysurfer_images_lh_rh(folder,suffix='cope1',hemi='lh',threshold=0.9499,coords=(),surface='inflated',fwhm=0,filename='',saveFolder=[],vmax=5.0,bsize=5):
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",hemi,surface, 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 = io.project_volume_data(mri_file, hemi, 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, min=smin, max=vmax, name="activation", hemi=hemi)
# brain.overlays["activation"]
# brain.add_overlay(surf_data_rh, min=smin, max=5, name="ang_corr_rh", hemi='rh')
if len(coords)>0:
if coords[0]>0:
hemi2='rh'
else:
hemi2='lh'
brain.add_foci(coords, map_surface="pial", color="gold",hemi=hemi2)
if len(saveFolder)>0:
folder=saveFolder
image_out=brain.save_montage('%s/%s-%s.png' % (folder,hemi,filename),order=['l','m'],orientation='h',border_size=bsize,colorbar=None)
else:
image_out=brain.save_image('%s/surfaceplot.jpg' % folder)
brain.close()
return image_out
示例10: plot_rs_surf
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [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
示例11: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [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()
示例12: plot_rs_surf_bh
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [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
示例13: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [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()
示例14:
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
sig2[sig2 < thresh] = 0
"""
A conjunction is defined as the minimum significance
value between the two maps at each vertex.
"""
conjunct = np.min(np.vstack((sig1, sig2)), axis=0)
"""
Now load the numpy array as an overlay.
Use a high saturation point so that the
blob will largely be colored with lower
values from the lookup table.
"""
brain.add_overlay(sig1, 4, 30, name="sig1")
"""
A pointer to the overlay's color manager
gets stored in the overlays dictionary.
Change the lookup table to "Reds" and turn the
color bar itself off, as otherwise the bars
for the three maps will get confusingly stacked.
"""
brain.overlays["sig1"].pos_bar.lut_mode = "Reds"
brain.overlays["sig1"].pos_bar.visible = False
"""
Now load the other two maps and again change
the lookup table and turn off the color bar itself.
"""
示例15: visOverlay
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_overlay [as 别名]
def visOverlay(pathToSurface, overlay, outputPath, hemi, type='white'):
brain = Brain(pathToSurface, hemi, type)
brain.add_overlay(overlay, -1, 1)
brain.show_view('lateral')
brain.save_imageset(outputPath, ['med', 'lat'], 'png')
brain.close()