本文整理汇总了Python中nilearn.plotting.plot_anat函数的典型用法代码示例。如果您正苦于以下问题:Python plot_anat函数的具体用法?Python plot_anat怎么用?Python plot_anat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了plot_anat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: plot_segmentation
def plot_segmentation(anat_file, segmentation, out_file,
**kwargs):
from nilearn.plotting import plot_anat
vmax = None
if kwargs.get('saturate', False):
import nibabel as nb
import numpy as np
vmax = np.percentile(nb.load(anat_file).get_data().reshape(-1),
70)
disp = plot_anat(
anat_file,
display_mode=kwargs.get('display_mode', 'ortho'),
cut_coords=kwargs.get('cut_coords', 8),
title=kwargs.get('title'),
vmax=vmax)
disp.add_contours(
segmentation,
levels=kwargs.get('levels', [1]),
colors=kwargs.get('colors', 'r'))
disp.savefig(out_file)
disp.close()
disp = None
return out_file
开发者ID:poldracklab,项目名称:mriqc,代码行数:25,代码来源:viz_utils.py
示例2: plot_segmentation
def plot_segmentation(anat_file, segmentation, out_file,
**kwargs):
from nilearn.plotting import plot_anat
vmax = kwargs.get('vmax')
vmin = kwargs.get('vmin')
if kwargs.get('saturate', False):
vmax = np.percentile(nb.load(anat_file).get_data().reshape(-1), 70)
if vmax is None and vmin is None:
vmin = np.percentile(nb.load(anat_file).get_data().reshape(-1), 10)
vmax = np.percentile(nb.load(anat_file).get_data().reshape(-1), 99)
disp = plot_anat(
anat_file,
display_mode=kwargs.get('display_mode', 'ortho'),
cut_coords=kwargs.get('cut_coords', 8),
title=kwargs.get('title'),
vmax=vmax, vmin=vmin)
disp.add_contours(
segmentation,
levels=kwargs.get('levels', [1]),
colors=kwargs.get('colors', 'r'))
disp.savefig(out_file)
disp.close()
disp = None
return out_file
开发者ID:oesteban,项目名称:mriqc,代码行数:29,代码来源:utils.py
示例3: plot_artifact
def plot_artifact(image_path, figsize=(20, 20), vmax=None, cut_coords=None, display_mode='ortho',
size=None):
import nilearn.plotting as nplt
fig = plt.figure(figsize=figsize)
nplt_disp = nplt.plot_anat(
image_path, display_mode=display_mode, cut_coords=cut_coords,
vmax=vmax, figure=fig, annotate=False)
if size is None:
size = figsize[0] * 6
bg_color = 'k'
fg_color = 'w'
ax = fig.gca()
ax.text(
.1, .95, 'L',
transform=ax.transAxes,
horizontalalignment='left',
verticalalignment='top',
size=size,
bbox=dict(boxstyle="square,pad=0", ec=bg_color, fc=bg_color, alpha=1),
color=fg_color)
ax.text(
.9, .95, 'R',
transform=ax.transAxes,
horizontalalignment='right',
verticalalignment='top',
size=size,
bbox=dict(boxstyle="square,pad=0", ec=bg_color, fc=bg_color),
color=fg_color)
return nplt_disp, ax
开发者ID:yingqiuz,项目名称:mriqc,代码行数:35,代码来源:misc.py
示例4: _plot_anat_with_contours
def _plot_anat_with_contours(image, segs=None, compress='auto',
**plot_params):
nsegs = len(segs or [])
plot_params = plot_params or {}
# plot_params' values can be None, however they MUST NOT
# be None for colors and levels from this point on.
colors = plot_params.pop('colors', None) or []
levels = plot_params.pop('levels', None) or []
missing = nsegs - len(colors)
if missing > 0: # missing may be negative
colors = colors + color_palette("husl", missing)
colors = [[c] if not isinstance(c, list) else c
for c in colors]
if not levels:
levels = [[0.5]] * nsegs
# anatomical
display = plot_anat(image, **plot_params)
# remove plot_anat -specific parameters
plot_params.pop('display_mode')
plot_params.pop('cut_coords')
plot_params['linewidths'] = 0.5
for i in reversed(range(nsegs)):
plot_params['colors'] = colors[i]
display.add_contours(segs[i], levels=levels[i],
**plot_params)
svg = extract_svg(display, compress=compress)
display.close()
return svg
开发者ID:poldracklab,项目名称:niworkflows,代码行数:34,代码来源:utils.py
示例5: _run_interface
def _run_interface(self, runtime):
import matplotlib
matplotlib.use('Agg')
import nibabel as nib
from nilearn import plotting, datasets, image
from nipype.interfaces.base import isdefined
import numpy as np
import pylab as plt
import os
wra_img = nib.load(self.inputs.wra_img)
canonical_img = nib.load(self.inputs.canonical_img)
title = self.inputs.title
mean_wraimg = image.mean_img(wra_img)
if title != "":
filename = title.replace(" ", "_")+".pdf"
else:
filename = "plot.pdf"
fig = plotting.plot_anat(mean_wraimg, title="wrafunc & canonical single subject", cut_coords=range(-40, 40, 10), display_mode='z')
fig.add_edges(canonical_img)
fig.savefig(filename)
fig.close()
self._plot = filename
runtime.returncode=0
return runtime
开发者ID:GordonMatthewson,项目名称:CosanlabToolbox,代码行数:29,代码来源:Nipype_SPM_Preproc.py
示例6: check_mask_coverage
def check_mask_coverage(epi,brainmask):
from os.path import abspath
from nipype import config, logging
config.enable_debug_mode()
logging.update_logging(config)
from nilearn import plotting
from nipype.interfaces.nipy.preprocess import Trim
trim = Trim()
trim.inputs.in_file = epi
trim.inputs.end_index = 1
trim.inputs.out_file = 'epi_vol1.nii.gz'
trim.run()
epi_vol = abspath('epi_vol1.nii.gz')
maskcheck_filename='maskcheck.png'
display = plotting.plot_anat(epi_vol, display_mode='ortho',
draw_cross=False,
title = 'brainmask coverage')
display.add_contours(brainmask,levels=[.5], colors='r')
display.savefig(maskcheck_filename)
display.close()
maskcheck_file = abspath(maskcheck_filename)
return(maskcheck_file)
开发者ID:catcamacho,项目名称:infant_rest,代码行数:25,代码来源:preprocessing_classic.py
示例7: _run_interface
def _run_interface(self, runtime):
import matplotlib
matplotlib.use("Agg")
import pylab as plt
wra_img = nib.load(self.inputs.wra_img)
canonical_img = nib.load(self.inputs.canonical_img)
title = self.inputs.title
mean_wraimg = image.mean_img(wra_img)
if title != "":
filename = title.replace(" ", "_") + ".pdf"
else:
filename = "plot.pdf"
fig = plotting.plot_anat(
mean_wraimg, title="wrafunc & canonical single subject", cut_coords=range(-40, 40, 10), display_mode="z"
)
fig.add_edges(canonical_img)
fig.savefig(filename)
fig.close()
self._plot = filename
runtime.returncode = 0
return runtime
开发者ID:burnash,项目名称:neurolearn,代码行数:27,代码来源:interfaces.py
示例8: make_anat_image
def make_anat_image(nifti_file,png_img_file=None):
"""Make anat image"""
nifti_file = str(nifti_file)
brain = plot_anat(nifti_file)
if png_img_file:
brain.savefig(png_img_file)
plt.close('all')
return brain
开发者ID:vsoch,项目名称:pybraincompare,代码行数:9,代码来源:image.py
示例9: anatomical_overlay
def anatomical_overlay(in_file, overlay_file, out_file):
import os.path
import matplotlib as mpl
mpl.use('Agg')
from nilearn.plotting import plot_anat as plot_anat
mask_display = plot_anat(in_file)
mask_display.add_edges(overlay_file)
mask_display.dim = -1
# mask_display.add_contours(overlay_file)
# mask_display.add_overlay(overlay_file)
mask_display.title(out_file, x=0.01, y=0.99, size=15, color=None,
bgcolor=None, alpha=1)
mask_display.savefig(out_file)
return os.path.abspath(out_file)
开发者ID:shoshber,项目名称:preprocessing-workflow,代码行数:14,代码来源:pipeline_reports.py
示例10: plot_image
def plot_image(input_files, output_directory, edge_file=None,
overlay_file=None,
contour_file=None, name=None, overlay_cmap=None):
""" Plot image with edge/overlay/contour on top (useful for checking
registration).
<unit>
<input name="input_files" type="['List_File', 'File']" desc="An image
or a list of image to be displayed."/>
<input name="output_directory" type="Directory" description="The
destination folder."/>
<input name="edge_file" type="File" description="The target image
to extract the edges from."/>
<input name="overlay_file" type="File" description="The target image
to extract the overlay from."/>
<input name="contour_file" type="File" description="The target image
to extract the contour from."/>
<input name="name" type="Str" description="The name of the plot."/>
<input name="overlay_cmap" type="Str" description="The color map to
use: 'cold_hot' or 'blue_red' or None."/>
<output name="snap_file" type="File" description="A pdf snap of the
image."/>
</unit>
"""
input_file = input_files[0]
# Check the input images exist on the file system
for in_file in [input_file, edge_file, overlay_file, contour_file]:
if in_file is not None and not os.path.isfile(in_file):
raise ValueError("'{0}' is not a valid filename.".format(in_file))
# Create the 'snap_file' location
snap_file = os.path.join(
output_directory, os.path.basename(input_file).split(".")[0] + ".pdf")
# Create the plot
display = plotting.plot_anat(input_file, title=name or "")
if edge_file is not None:
display.add_edges(edge_file)
if overlay_file is not None:
cmap = plotting.cm.__dict__.get(
overlay_cmap, plotting.cm.alpha_cmap((1, 1, 0)))
display.add_overlay(overlay_file, cmap=cmap)
if contour_file is not None:
display.add_contours(contour_file, alpha=0.6, filled=True,
linestyles="solid")
display.savefig(snap_file)
display.close()
return snap_file
开发者ID:neurospin,项目名称:caps-mmutils,代码行数:49,代码来源:slicer.py
示例11: create_coreg_plot
def create_coreg_plot(epi,anat):
import os
from nipype import config, logging
config.enable_debug_mode()
logging.update_logging(config)
from nilearn import plotting
coreg_filename='coregistration.png'
display = plotting.plot_anat(epi, display_mode='ortho',
draw_cross=False,
title = 'coregistration to anatomy')
display.add_edges(anat)
display.savefig(coreg_filename)
display.close()
coreg_file = os.path.abspath(coreg_filename)
return(coreg_file)
开发者ID:catcamacho,项目名称:infant_rest,代码行数:17,代码来源:preprocessing_classic.py
示例12: edges_overlay
def edges_overlay(input_file, template_file, prefix="e", output_directory=None):
""" Plot image outline on top of another image (useful for checking
registration)
<unit>
<input name="input_file" type="File" desc="An image to display."/>
<input name="template_file" type="File" desc="The target image to
extract the edges from."/>
<input name="prefix" type="String" desc="the prefix of the result
file."/>
<input name="output_directory" type="Directory" desc="The destination
folder." optional="True"/>
<output name="edges_file" type="File" desc="A snap with two overlayed
images."/>
</unit>
"""
# Check the input images exist on the file system
for in_file in [input_file, template_file]:
if not os.path.isfile(in_file):
raise ValueError("'{0}' is not a valid filename.".format(in_file))
# Check that the outdir is valid
if output_directory is not None:
if not os.path.isdir(output_directory):
raise ValueError("'{0}' is not a valid directory.".format(output_directory))
else:
output_directory = os.path.dirname(input_file)
# Create the plot
display = plotting.plot_anat(input_file, title="Overlay")
display.add_edges(template_file)
edges_file = os.path.join(output_directory, prefix + os.path.basename(input_file).split(".")[0] + ".pdf")
display.savefig(edges_file)
display.close()
return edges_file
开发者ID:rcherbonnier,项目名称:caps-clinfmri,代码行数:36,代码来源:image_overlay.py
示例13: print
# is a 'nibabel' object. It has data, and an affine
anat_data = smooth_anat_img.get_data()
print('anat_data has shape: %s' % str(anat_data.shape))
anat_affine = smooth_anat_img.get_affine()
print('anat_affineaffine:\n%s' % anat_affine)
# Finally, it can be passed to nilearn function
smooth_anat_img = image.smooth_img(smooth_anat_img, 3)
#########################################################################
# Visualization
from nilearn import plotting
cut_coords = (0, 0, 0)
# Like all functions in nilearn, plotting can be given filenames
plotting.plot_anat(anat_filename, cut_coords=cut_coords,
title='Anatomy image')
# Or nibabel objects
plotting.plot_anat(smooth_anat_img,
cut_coords=cut_coords,
title='Smoothed anatomy image')
#########################################################################
# Saving image to file
smooth_anat_img.to_filename('smooth_anat_img.nii.gz')
#########################################################################
# Finally, showing plots when used inside a terminal
plotting.show()
开发者ID:GaelVaroquaux,项目名称:nilearn,代码行数:30,代码来源:plot_nilearn_101.py
示例14: Structure
#
# .. note:: In this tutorial, we load the data using a data downloading
# function. To input your own data, you will need to provide
# a list of paths to your own files in the ``subject_data`` variable.
# These should abide to the Brain Imaging Data Structure (BIDS)
# organization.
from nistats.datasets import fetch_spm_auditory
subject_data = fetch_spm_auditory()
print(subject_data.func) # print the list of names of functional images
###############################################################################
# We can display the first functional image and the subject's anatomy:
from nilearn.plotting import plot_stat_map, plot_anat, plot_img, show
plot_img(subject_data.func[0])
plot_anat(subject_data.anat)
###############################################################################
# Next, we concatenate all the 3D EPI image into a single 4D image,
# then we average them in order to create a background
# image that will be used to display the activations:
from nilearn.image import concat_imgs, mean_img
fmri_img = concat_imgs(subject_data.func)
mean_img = mean_img(fmri_img)
###############################################################################
# Specifying the experimental paradigm
# ------------------------------------
#
# We must now provide a description of the experiment, that is, define the
开发者ID:alpinho,项目名称:nistats,代码行数:31,代码来源:plot_single_subject_single_run.py
示例15: coord_transform
# Build the mean image because we have no anatomic data
from nilearn import image
func_filename = haxby_dataset.func[0]
mean_img = image.mean_img(func_filename)
z_slice = -24
from nilearn.image.resampling import coord_transform
affine = mean_img.get_affine()
_, _, k_slice = coord_transform(0, 0, z_slice,
linalg.inv(affine))
k_slice = round(k_slice)
fig = plt.figure(figsize=(4, 5.4), facecolor='k')
from nilearn.plotting import plot_anat
display = plot_anat(mean_img, display_mode='z', cut_coords=[z_slice],
figure=fig)
mask_vt_filename = haxby_dataset.mask_vt[0]
mask_house_filename = haxby_dataset.mask_house[0]
mask_face_filename = haxby_dataset.mask_face[0]
display.add_contours(mask_vt_filename, contours=1, antialiased=False,
linewidths=4., levels=[0], colors=['red'])
display.add_contours(mask_house_filename, contours=1, antialiased=False,
linewidths=4., levels=[0], colors=['blue'])
display.add_contours(mask_face_filename, contours=1, antialiased=False,
linewidths=4., levels=[0], colors=['limegreen'])
# We generate a legend using the trick described on
# http://matplotlib.sourceforge.net/users/legend_guide.httpml#using-proxy-artist
from matplotlib.patches import Rectangle
p_v = Rectangle((0, 0), 1, 1, fc="red")
p_h = Rectangle((0, 0), 1, 1, fc="blue")
开发者ID:andreas-koukorinis,项目名称:gaelvaroquaux.github.io,代码行数:32,代码来源:plot_haxby_masks.py
示例16: MyConnectome2015Dataset
"""
Docstring.
"""
from nidata.multimodal import MyConnectome2015Dataset
# runs the member function 'fetch' from the class 'Laumann2015Dataset'
dataset = MyConnectome2015Dataset().fetch(data_types=['functional'],
session_ids=range(2, 13))
print(dataset)
from nilearn.plotting import plot_anat
from nilearn.image import index_img
from matplotlib import pyplot as plt
plot_anat(index_img(dataset['functional'][0], 0))
plt.show()
开发者ID:JohnGriffiths,项目名称:nidata,代码行数:16,代码来源:example1.py
示例17: Memory
from nipype.caching import Memory
cache_directory = "/tmp"
mem = Memory("/tmp")
os.chdir(cache_directory)
# Compute mean functional
from procasl import preprocessing
average = mem.cache(preprocessing.Average)
out_average = average(in_file=heroes["raw ASL"][0])
mean_func = out_average.outputs.mean_image
# Coregister anat to mean functional
from nipype.interfaces import spm
coregister = mem.cache(spm.Coregister)
out_coregister = coregister(target=mean_func, source=raw_anat, write_interp=3)
# Check coregistration
import matplotlib.pylab as plt
from nilearn import plotting
for anat, label in zip([raw_anat, out_coregister.outputs.coregistered_source], ["native", "coregistered"]):
figure = plt.figure(figsize=(5, 4))
display = plotting.plot_anat(
anat, figure=figure, display_mode="z", cut_coords=(-66,), title=label + " anat edges on mean functional"
)
display.add_edges(mean_func)
plotting.show()
开发者ID:process-asl,项目名称:process-asl,代码行数:30,代码来源:plot_heroes_coregister.py
示例18: openAnatomy
def openAnatomy(self):
file = self.onOpen([('NIFTI files', '*.nii.gz'), ('All files', '*')])
print("anatomy file: " + file)
plotting.plot_anat(file, title='Anatomy')
plt.show()
开发者ID:niallmcs,项目名称:brainProject,代码行数:5,代码来源:gui_demo.py
示例19: plot_image
def plot_image(input_file, edge_file=None, overlay_file=None, contour_file=None,
snap_file=None, name=None, overlay_cmap=None,
cut_coords=None):
""" Plot image with edge/overlay/contour on top (useful for checking
registration).
Parameters
----------
input_file: str (mandatory)
An image to display.
outline_file: str (optional, default None)
The target image to extract the edges from.
snap_file: str (optional, default None)
The destination file: if not specified will be the 'input_file'
name with a 'png' extension.
name: str (optional, default None)
The name of the plot.
overlay_cmap: str (optional, default None)
The color map to use: 'cold_hot' or 'blue_red' or None,
or a N*4 array with values in 0-1 (r, g, b, a).
cut_coords: 3-uplet (optional, default None)
The MNI coordinates of the point where the cut is performed.
If None is given, the cuts is calculated automaticaly.
Returns
-------
snap_file: str
A pdf snap of the image.
"""
# Check the input images exist on the file system
for in_file in [input_file, edge_file, overlay_file, contour_file]:
if in_file is not None and not os.path.isfile(in_file):
raise ValueError("'{0}' is not a valid filename.".format(in_file))
# Check that the snap_file has been specified
if snap_file is None:
snap_file = input_file.split(".")[0] + ".png"
# Create the plot
display = plotting.plot_anat(input_file, title=name or "",
cut_coords=cut_coords)
if edge_file is not None:
display.add_edges(edge_file)
if overlay_file is not None:
# Create a custom discrete colormap
if isinstance(overlay_cmap, numpy.ndarray):
cmap = colors.LinearSegmentedColormap.from_list(
"my_colormap", overlay_cmap)
#cmap, _ = colors.from_levels_and_colors(
# range(overlay_cmap.shape[0] + 1), overlay_cmap)
# This is probably a matplotlib colormap
elif overlay_cmap in dir(plotting.cm):
cmap = getattr(plotting.cm, overlay_cmap)
# Default
else:
cmap = plotting.cm.alpha_cmap((1, 1, 0))
display.add_overlay(overlay_file, cmap=cmap)
if contour_file is not None:
display.add_contours(contour_file, alpha=0.6, filled=True,
linestyles="solid")
display.savefig(snap_file)
display.close()
return snap_file
开发者ID:AGrigis,项目名称:caps-clindmri,代码行数:66,代码来源:slicer.py
示例20: image
# Loop through all the slices in this dimension
for i in np.arange(img_reslice.shape[dim_lookup_dict[axis]], dtype='float'):
# Test to see if there is anything worth showing in the image
# If the anat image (img) is empty then don't make a picture
if slice_dict[axis](i, img).mean() == 0.0:
continue
# Get the co-ordinate you want
coord = coord_transform_dict[axis](i, img_reslice)
# Make the image
slicer = plotting.plot_anat(img_reslice,
threshold=None,
cmap=cmap,
display_mode=axis,
black_bg=black_bg,
annotate=annotate,
draw_cross=draw_cross,
cut_coords=(coord,))
# Add the overlay if given
if not overlay_file is None:
slicer.add_overlay(overlay_img_reslice, cmap=overlay_cmap)
# Save the png file
output_file = os.path.join(pngs_dir,
'{}_{:03.0f}{}.png'.format(label_lookup_dict[axis],
i,
overlay_name))
slicer.savefig(output_file, dpi=dpi)
开发者ID:KirstieJane,项目名称:BrainsForPublication,代码行数:32,代码来源:subj_anat_gif.py
注:本文中的nilearn.plotting.plot_anat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论