def volume_images(data_dir, subj): """Plot a mosiac of the brainmask and aseg volumes.""" # Plot the volume slices brain_file = op.join(data_dir, subj, "mri/brainmask.mgz") # Load the cortical ribbon file and use same index for both hemis ribbon_file = op.join(data_dir, subj, "mri/ribbon.mgz") ribbon_data = nib.load(ribbon_file).get_data().astype(float) ribbon_data[ribbon_data == 3] = 1 ribbon_data[ribbon_data == 42] = 1 ribbon_data[ribbon_data != 1] = np.nan # Load the aseg file and use it to derive a FOV mask aseg_file = op.join(data_dir, subj, "mri/aseg.mgz") aseg_data = nib.load(aseg_file).get_data() aseg_data[aseg_data == 41] = 2 mask_data = (aseg_data > 0).astype(int) # Load the lookup table for the aseg volume aseg_lut = np.genfromtxt( op.join(os.environ["FREESURFER_HOME"], "FreeSurferColorLUT.txt")) # Draw the brainmask and cortical ribbon m = Mosaic(brain_file, ribbon_data, mask_data, step=3) m.plot_mask("#C41E3A") m.savefig(op.join(data_dir, subj, "snapshots/volume.png")) m.close() # Draw the brainmask and cortical ribbon aseg_cmap = mpl.colors.ListedColormap(aseg_lut[:64, 2:5] / 255) m = Mosaic(brain_file, aseg_data, mask_data, step=3) m.plot_overlay(aseg_cmap, vmin=0, vmax=63, alpha=.75, colorbar=False) m.savefig(op.join(data_dir, subj, "snapshots/aseg.png")) m.close()
def volume_images(data_dir, subj): """Plot a mosiac of the brainmask and aseg volumes.""" # Plot the volume slices brain_file = op.join(data_dir, subj, "mri/brainmask.mgz") # Load the cortical ribbon file and use same index for both hemis ribbon_file = op.join(data_dir, subj, "mri/ribbon.mgz") ribbon_data = nib.load(ribbon_file).get_data().astype(float) ribbon_data[ribbon_data == 3] = 1 ribbon_data[ribbon_data == 42] = 1 ribbon_data[ribbon_data != 1] = np.nan # Load the aseg file and use it to derive a FOV mask aseg_file = op.join(data_dir, subj, "mri/aseg.mgz") aseg_data = nib.load(aseg_file).get_data() aseg_data[aseg_data == 41] = 2 mask_data = (aseg_data > 0).astype(int) # Load the lookup table for the aseg volume aseg_lut = np.genfromtxt(op.join(os.environ["FREESURFER_HOME"], "FreeSurferColorLUT.txt")) # Draw the brainmask and cortical ribbon m = Mosaic(brain_file, ribbon_data, mask_data, step=3) m.plot_mask("#C41E3A") m.savefig(op.join(data_dir, subj, "snapshots/volume.png")) m.close() # Draw the brainmask and cortical ribbon aseg_cmap = mpl.colors.ListedColormap(aseg_lut[:64, 2:5] / 255) m = Mosaic(brain_file, aseg_data, mask_data, step=3) m.plot_overlay(aseg_cmap, vmin=0, vmax=63, alpha=.75, colorbar=False) m.savefig(op.join(data_dir, subj, "snapshots/aseg.png")) m.close()
def plot_mask_image(self): m = Mosaic(self.inputs.orig_file, self.inputs.mask_file, self.inputs.mask_file, show_mask=False, step=1) m.plot_mask() m.savefig("functional_mask.png") m.close()
def plot_mask(self): """Plot the analysis mask.""" m = Mosaic(stat=self.inputs.mask_file) m.plot_mask() out_fname = nii_to_png(self.inputs.mask_file) self.out_files.append(out_fname) m.savefig(out_fname) m.close()