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()
def test_contour(): """Test plotting of contour overlay.""" _set_backend() brain = Brain(*std_args) overlay_file = pjoin(data_dir, "lh.sig.nii.gz") brain.add_contour_overlay(overlay_file) brain.add_contour_overlay(overlay_file, max=20, n_contours=9, line_width=2) brain.contour['surface'].actor.property.line_width = 1 brain.contour['surface'].contour.number_of_contours = 10 brain.close()
"inflated", config_opts={ "cortex": "low_contrast", "background": "#151540" }) """ Get a path to the overlay file """ overlay_file = op.join("example_data", "lh.sig.nii.gz") """ Add the contour overlay with the default display settings Contours overlays only ever use the positive components of your image, but they get threshold and colormap saturation from your configuration settings just as normal overlays do. """ brain.add_contour_overlay(overlay_file) """ The Brain object can only display one contour overlay at a time, So if we bring up another one, it will remove the original overlay behind the scenes for us. Here let's specify a different number of contours and use a different line width. """ brain.add_contour_overlay(overlay_file, max=20, n_contours=9, line_width=2) """ At the moment, the Brain object itself does not expose an interface to manipulate what the contour overlay looks like after it has been loaded, but if you know a little bit about the underlying Mayavi engine, you can control aspects of the visualization through the contour dictionary attribute. """ brain.contour['surface'].actor.property.line_width = 1
brain = Brain("fsaverage", "lh", "inflated", config_opts={"cortex": "low_contrast", "background": "#151540"}) """ Get a path to the overlay file """ overlay_file = op.join("example_data", "lh.sig.nii.gz") """ Add the contour overlay with the default display settings Contours overlays only ever use the positive components of your image, but they get threshold and colormap saturation from your configuration settings just as normal overlays do. """ brain.add_contour_overlay(overlay_file) """ The Brain object can only display one contour overlay at a time, So if we bring up another one, it will remove the original overlay behind the scenes for us. Here let's specify a different number of contours and use a different line width. """ brain.add_contour_overlay(overlay_file, max=20, n_contours=9, line_width=2) """ At the moment, the Brain object itself does not expose an interface to manipulate what the contour overlay looks like after it has been
of PySurfer using the Freesurfer program ``mri_surf2surf``). With a perfect transformation, the contour lines should follow the light/dark gray boundary on the fsaverage surface. Large deviations may reflect problems with the underlying data that you should investigate. """ import nibabel as nib from surfer import Brain brain = Brain("fsaverage", "both", "inflated") for hemi in ["lh", "rh"]: # This file was created with mri_surf2surf curv = nib.load("example_data/%s.curv.fsaverage.mgz" % hemi) # Binarize the curvature at 0 curv_bin = (curv.get_data() > 0).squeeze() # Add the data as a contour overlay, but turn off the colorbar brain.add_contour_overlay(curv_bin, min=0, max=1.5, n_contours=2, line_width=3, hemi=hemi) brain.contour_list[-1]["colorbar"].visible = False brain.show_view("dorsal")
Freesurfer's curvature-driven normalization to a common template. We are going to plot the contour of the subject's curvature estimate after transforming that map into the common space (this step is performed outside of PySurfer using the Freesurfer program ``mri_surf2surf``). With a perfect transformation, the contour lines should follow the light/dark gray boundary on the fsaverage surface. Large deviations may reflect problems with the underlying data that you should investigate. """ import nibabel as nib from surfer import Brain brain = Brain("fsaverage", "both", "inflated") for hemi in ["lh", "rh"]: # This file was created with mri_surf2surf curv = nib.load("example_data/%s.curv.fsaverage.mgz" % hemi) # Binarize the curvature at 0 curv_bin = (curv.get_data() > 0).squeeze() # Add the data as a contour overlay, but turn off the colorbar brain.add_contour_overlay(curv_bin, min=0, max=1.5, n_contours=2, line_width=3, hemi=hemi) brain.contour_list[-1]["colorbar"].visible = False brain.show_view("dorsal")
brain.add_overlay(surf_data, name=name_overlay, hemi=hemi) overlay_roi = brain.overlays[name_overlay] lut = overlay_roi.pos_bar.lut.table.to_array() # lut = np.zeros((255, 4)) # print lut.shape lut[0:256, 0:3] = color_list[cpt_color] # lut[0:255, 0:3] = [255, 255, 0] lut_alpha = lut lut_alpha[0:256, 3] = 100 # change opacity for the roi overlay_roi.pos_bar.lut.table = lut # Add topographic contours brain.add_contour_overlay(surf_data, min=0, max=10, n_contours=10, colormap = lut, line_width=1, remove_existing=False, colorbar = False) # Save in png #brain.save_imageset(save_png, ['lat'], 'png', colorbar=None) # Color cpt cpt_color += 1 # If you just want one roi by one # Remove for the next roi # for overlay in brain.overlays_dict[name_overlay]: # overlay.remove()
def surface_roi_contour(subjects_dir, subject_id, hemi, surf, alpha, coords, region): """ Bring up the visualization. Add the contour of region. """ brain = Brain(subjects_dir=subjects_dir, subject_id=subject_id, hemi=hemi, surf=surf, alpha=alpha) if hemi == 'both': brain.add_contour_overlay(region[0], min=region[0].min(), max=region[0].max(), n_contours=2, line_width=1.5, colormap="YlOrRd_r", hemi='lh', remove_existing=True, colorbar=False) brain.add_overlay(coords[0], min=coords[0][coords[0] > 0].min(), max=coords[0].max(), sign='pos', hemi='lh', name='lh') brain.add_contour_overlay(region[1], min=region[1].min(), max=region[1].max(), n_contours=2, line_width=1.5, colormap="YlOrRd_r", hemi='rh', remove_existing=False, colorbar=False) brain.add_overlay(coords[1], min=coords[1][coords[1] > 0].min(), max=coords[1].max(), sign='pos', hemi='rh', name='rh') elif hemi == 'lh': brain.add_contour_overlay(region[0], min=region[0].min(), max=region[0].max(), n_contours=2, line_width=1.5, colormap="YlOrRd_r", hemi='lh', remove_existing=True, colorbar=False) brain.add_overlay(coords[0], min=coords[0][coords[0] > 0].min(), max=coords[0].max(), sign='pos', hemi='lh', name='lh') else: brain.add_contour_overlay(region[1], min=region[1].min(), max=region[1].max(), n_contours=2, line_width=1.5, colormap="YlOrRd_r", hemi='rh', remove_existing=True, colorbar=False) brain.add_overlay(coords[1], min=coords[1][coords[1] > 0].min(), max=coords[1].max(), sign='pos', hemi='rh', name='rh') mlab.show()
This example shows how PySurfer can be used to examine the quality of Freesurfer's curvature-driven normalization to a common template. We are going to plot the contour of the subject's curvature estimate after transforming that map into the common space (this step is performed outside of PySurfer using the Freesurfer program ``mri_surf2surf``). With a perfect transformation, the contour lines should follow the light/dark gray boundary on the fsaverage surface. Large deviations may reflect problems with the underlying data that you should investigate. """ import nibabel as nib from surfer import Brain brain = Brain("fsaverage", "both", "inflated") for hemi in ["lh", "rh"]: # This file was created with mri_surf2surf curv = nib.load("example_data/%s.curv.fsaverage.mgz" % hemi) # Binarize the curvature at 0 curv_bin = (curv.get_data() > 0).squeeze() # Add the data as a contour overlay, but turn off the colorbar brain.add_contour_overlay(curv_bin, 0, 1.15, 2, 3, hemi=hemi) brain.contour_list[-1]["colorbar"].visible = False brain.show_view("dorsal")