本文整理汇总了Python中surfer.Brain.save_montage方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.save_montage方法的具体用法?Python Brain.save_montage怎么用?Python Brain.save_montage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类surfer.Brain
的用法示例。
在下文中一共展示了Brain.save_montage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visMontage
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [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
示例2: corr_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [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
示例3: make_brain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [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
示例4: img2disc
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [as 别名]
def img2disc(data, foci_all=False, foci_dmn=False, labelfile=False, hemi='lh', filename='temp.png'):
brain = Brain('fsaverage5', hemi, 'inflated', curv=False)
brain.add_data(data, data.min(), data.max(), colormap="spectral", alpha=0.6)
if labelfile:
brain.add_label(labelfile, borders=True, color='grey')
if foci_all:
brain.add_foci(foci_all, coords_as_verts=True, scale_factor=.5, color='black')
if foci_dmn:
brain.add_foci(foci_dmn, coords_as_verts=True, scale_factor=.7, color='blue')
brain.save_montage(filename, order=['lat', 'med'], orientation='h', border_size=10)
示例5: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [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()
示例6: visMorph
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [as 别名]
def visMorph(pathToSurface, overlay, outputPath, hemi):
'''
Display anything morphometric
'''
# check the overlay
if (not overlay == 'sulc' and not overlay == 'thickness'
and not overlay == 'curv'):
message = ('You specified %s as overlay, this doesn\'t make sense'
% (overlay))
raise Exception(message)
brain = Brain(pathToSurface, hemi, 'white')
brain.add_morphometry(overlay)
brain.save_montage(outputPath, ['l', 'm'], orientation='v')
brain.close()
示例7: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [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()
示例8: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [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()
示例9: make_pysurfer_images_lh_rh
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [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: Brain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [as 别名]
======================
Make one image from multiple views.
"""
print __doc__
from surfer import Brain
sub = 'fsaverage'
hemi = 'lh'
surf = 'inflated'
bgcolor = 'w'
brain = Brain(sub, hemi, surf, config_opts={'background': bgcolor})
###############################################################################
# Get a set of images as a montage, note the data could be saved if desired
image = brain.save_montage(None, ['l', 'v', 'm'], orientation='v')
brain.close()
###############################################################################
# View created image
import pylab as pl
fig = pl.figure(figsize=(5, 3), facecolor=bgcolor)
ax = pl.axes(frameon=False)
ax.imshow(image, origin='upper')
pl.xticks(())
pl.yticks(())
pl.draw()
pl.show()
示例11: vizBrain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [as 别名]
def vizBrain(data, subject_id='fsaverage5', hemi='lh', surface='pial', filename='brain.png'):
brain = Brain(subject_id, hemi, surface)
dmin = data.min()#+(data.std()/2)
dmax = data.max()#-(data.std()/2)
brain.add_data(data, dmin, dmax, colormap="hot", alpha=0.7)
brain.save_montage(filename, order=['lat', 'med'], orientation='h', border_size=10)
示例12: Brain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [as 别名]
subjects_dir = op.join(data_path, "subjects")
os.environ['SUBJECTS_DIR'] = subjects_dir
subject_id = "Bend1"
hemi = "lh"
surf = "pial"
bgcolor = 'w'
brain = Brain(subject_id, hemi, surf, config_opts={'background': bgcolor},
subjects_dir=subjects_dir)
volume_file = op.abspath("example_fspet/corrected_pet_to_t1/_subject_id_Bend1/r_volume_MGRousset_flirt.nii")
pet = project_volume_data(volume_file, hemi,
subject_id=subject_id)
brain.add_data(pet, min=250, max=12000,
colormap="jet", alpha=.6, colorbar=True)
image = brain.save_montage("Example_FDG-PET.png", ['l', 'd', 'm'], orientation='v')
brain.close()
###############################################################################
# View created image
import pylab as pl
fig = pl.figure(figsize=(5, 3), facecolor=bgcolor)
ax = pl.axes(frameon=False)
ax.imshow(image, origin='upper')
pl.draw()
pl.show()
示例13: len
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [as 别名]
surf_data = surf_data.squeeze()
surf_f = '%s/fsaverage5/surf/%s.orig' % (fsDir, hemi)
surf_faces = nib.freesurfer.io.read_geometry(surf_f)[1]
mask = np.zeros((10242))
while True in np.isnan(surf_data):
nans = np.unique(np.where(np.isnan(surf_data))[0])
mask[nans] = 1
bad = []
good = {}
for node in nans:
neighbors = np.unique(surf_faces[np.where(np.in1d(surf_faces.ravel(), [node]).reshape(surf_faces.shape))[0]])
bad_neighbors = neighbors[np.unique(np.where(np.isnan(surf_data[neighbors]))[0])]
good_neighbors = np.setdiff1d(neighbors, bad_neighbors)
bad.append((node, len(bad_neighbors)))
good[node] = good_neighbors
bad = np.array(bad).transpose()
nodes_with_least_bad_neighbors = bad[0][bad[1] == np.min(bad[1])]
for node in nodes_with_least_bad_neighbors:
surf_data[node] = np.mean(surf_data[list(good[node])], axis=0)
surf_img._data = np.expand_dims(np.expand_dims(surf_data, axis=1), axis=1)
brain = Brain('fsaverage5', hemi, 'pial', curv=False)
brain.add_data(mask, mask.min(), mask.max(), colormap="spectral", alpha=0.6)
brain.save_montage(mask_img_f, order=['lat', 'med'], orientation='h', border_size=10)
np.save(mask_f, mask)
else:
surf_img._data = surf_data
surf_img.to_filename(rest_interp_f)
示例14: len
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [as 别名]
roi_data = data_to_plot[pos]
"""
Make a vector containing the data point at each vertex.
"""
vtx_data = roi_data[labels]
# Check if there are akwardly labelled regions and reset their values
if len(np.where(labels==-1)[0]) > 0:
vtx_data[np.where(labels==-1)] = default_value
"""
Display these values on the brain. Use a sequential colormap (assuming
these data move from low to high values), and add an alpha channel so the
underlying anatomy is visible.
"""
brain.add_data(vtx_data, min=vtx_data.min(), max=vtx_data.max(), colormap="jet", alpha=.6)
image = brain.save_montage("Example_FDG-PET_FreesurferRegions.png", ['l', 'd', 'm'], orientation='v')
brain.close()
###############################################################################
# View created image
import pylab as pl
fig = pl.figure(figsize=(5, 3), facecolor=bgcolor)
ax = pl.axes(frameon=False)
ax.imshow(image, origin='upper')
pl.draw()
pl.show()
示例15: Brain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_montage [as 别名]
Make a multiview image
======================
Make one image from multiple views.
"""
print __doc__
from surfer import Brain
sub = 'fsaverage'
hemi = 'lh'
surf = 'inflated'
brain = Brain(sub, hemi, surf)
###############################################################################
# Save a set of images as a montage
brain.save_montage('/tmp/fsaverage_h_montage.png', ['l', 'v', 'm'], orientation='v')
brain.close()
###############################################################################
# View created image
import Image
import pylab as pl
image = Image.open('/tmp/fsaverage_h_montage.png')
fig = pl.figure(figsize=(5,3))
pl.imshow(image, origin='lower')
pl.xticks(())
pl.yticks(())