Skip to content

t_initAnatomyFromFreesurfer

Jonathan Winawer edited this page Jul 21, 2016 · 5 revisions
<title>t_initAnatomyFromFreesurfer</title><style type="text/css"> html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}

html { min-height:100%; margin-bottom:1px; } html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; } html body td { vertical-align:top; text-align:left; }

h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; } h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; } h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; }

a { color:#005fce; text-decoration:none; } a:hover { color:#005fce; text-decoration:underline; } a:visited { color:#004aa0; text-decoration:none; }

p { padding:0px; margin:0px 0px 20px; } img { padding:0px; margin:0px 0px 20px; border:none; } p img, pre img, tt img, li img, h1 img, h2 img { margin-bottom:0px; }

ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; } ul li { padding:0px; margin:0px 0px 7px 0px; } ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; } ul li ol li { list-style:decimal; } ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; } ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; } ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; } ol li ol li { list-style-type:lower-alpha; } ol li ul { padding-top:7px; } ol li ul li { list-style:square; }

.content { font-size:1.2em; line-height:140%; padding: 20px; }

pre, code { font-size:12px; } tt { font-size: 1.2em; } pre { margin:0px 0px 20px; } pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; } pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; } pre.error { color:red; }

@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } }

span.keyword { color:#0000FF } span.comment { color:#228B22 } span.string { color:#A020F0 } span.untermstring { color:#B20000 } span.syscmd { color:#B28C00 }

.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; } .footer p { margin:0px; } .footer a { color:#878787; } .footer a:hover { color:#878787; text-decoration:underline; } .footer a:visited { color:#878787; }

table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; } table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; }

</style>

t_initAnatomyFromFreesurfer

Illustrates how to initialize the volume anatomy and class file from a freesurfer directory. Uses the sample freesurfer data set ernie

Dependencies: Freesurfer Remote Data Toolbox

Summary

- Download freesurfer ernie directory - Create t1 anatomy and t1 class files from freesurfer - Visualize the two images

Tested 07/20/2016 - MATLAB r2015a, Mac OS 10.11.6

See also: t_initVistaSession

Winawer lab (NYU)

Contents

Download ernie freesurfer directory

% Check whether freesurfer paths exist
fssubjectsdir = getenv('SUBJECTS_DIR');
if isempty(fssubjectsdir)
error('Freesurfer paths not found. Cannot proceed.')
end

% Get ernie freesufer1 directory and install it in freesurfer subjects dir % If we find the directory, do not bother unzipping again forceOverwrite = false;

% Do it dataDir = mrtInstallSampleData('anatomy/freesurfer', 'ernie', ... fssubjectsdir, forceOverwrite);

fprintf('Freesurfer directory for ernie installed here:\n %s\n', dataDir)

Data directory /Volumes/server/Freesurfer_subjects/ernie already exists. Skipping unzip.
Freesurfer directory for ernie installed here:
/Volumes/server/Freesurfer_subjects/ernie

Create t1 anatomy and t1 class files from freesurfer

Store current directory

curdir = pwd();

% This is the path where we will set up the vista session erniePathTemp = fullfile(vistaRootPath, 'local', 'scratch', 'erniePRF'); mkdir(erniePathTemp);

% Navigate cd(erniePathTemp)

% Create t1 anatomy and class file mkdir 3DAnatomy; outfile = fullfile('3DAnatomy', 't1_class.nii.gz'); fillWithCSF = true; alignTo = 'orig.mgz'; fs_ribbon2itk('ernie', outfile, fillWithCSF, alignTo);

% Check that you created a t1 class file (ribbon) and t1 anatomy ls 3DAnatomy

% The command window should show: % t1.nii.gz t1_class.nii.gz

Warning: Directory already exists.
Warning: Directory already exists.
mri_convert -rt nearest /Volumes/server/Freesurfer_subjects/ernie/mri/orig.mgz 3DAnatomy/t1.nii.gz
$Id: mri_convert.c,v 1.179.2.7 2012/09/05 21:55:16 mreuter Exp $
reading from /Volumes/server/Freesurfer_subjects/ernie/mri/orig.mgz...
TR=0.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (-1, 0, 0)
j_ras = (0, 0, -1)
k_ras = (0, 1, 0)
writing to 3DAnatomy/t1.nii.gz...
mri_convert --reslice_like 3DAnatomy/t1.nii.gz -rt nearest /Volumes/server/Freesurfer_subjects/ernie/mri/ribbon.mgz 3DAnatomy/t1_class.nii.gz
$Id: mri_convert.c,v 1.179.2.7 2012/09/05 21:55:16 mreuter Exp $
reading from /Volumes/server/Freesurfer_subjects/ernie/mri/ribbon.mgz...
TR=0.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (-1, 0, 0)
j_ras = (0, 0, -1)
k_ras = (0, 1, 0)
reading template info from volume 3DAnatomy/t1.nii.gz...
writing to 3DAnatomy/t1_class.nii.gz...

Converting voxels....

Number of L Gray voxels = 268982 Number of L White voxels = 299585 Number of R White voxels = 302175 Number of R Gray voxels = 274456 t1.nii.gz t1_class.nii.gz

Visualize

% Show the volume anatomy, segmentation, and anatomy masked by segmentation
ni = niftiRead(fullfile('3DAnatomy', 't1.nii.gz'));
t1 = niftiGet(ni, 'data');
ni = niftiRead(fullfile('3DAnatomy', 't1_class.nii.gz'));
cl = niftiGet(ni, 'data');

fH = figure('Color','w');

subplot(1,3,1) imagesc(t1(:,:,128), [0 255]); colormap gray; axis image title('Volume anatomy')

subplot(1,3,2) imagesc(cl(:,:,128), [1 6]); axis image title('Class file')

subplot(1,3,3) mask = cl(:,:,128) > 1; imagesc(t1(:,:,128) .* uint8(mask)); axis image title('Masked anatomy')

Clean up

cd(curdir)


Published with MATLAB® R2015a

<!--
SOURCE BEGIN

%% t_initAnatomyFromFreesurfer % % Illustrates how to initialize the volume anatomy and class file from a % freesurfer directory. Uses the sample freesurfer data set % % Dependencies: % Freesurfer % Remote Data Toolbox % % Summary % % - Download freesurfer ernie directory % - Create t1 anatomy and t1 class files from freesurfer % - Visualize the two images % % Tested 07/20/2016 - MATLAB r2015a, Mac OS 10.11.6 % % See also: t_initVistaSession % % Winawer lab (NYU)

%% Download ernie freesurfer directory

% Check whether freesurfer paths exist fssubjectsdir = getenv('SUBJECTS_DIR'); if isempty(fssubjectsdir) error('Freesurfer paths not found. Cannot proceed.') end

% Get ernie freesufer1 directory and install it in freesurfer subjects dir % If we find the directory, do not bother unzipping again forceOverwrite = false;

% Do it dataDir = mrtInstallSampleData('anatomy/freesurfer', 'ernie', ... fssubjectsdir, forceOverwrite);

fprintf('Freesurfer directory for ernie installed here:\n %s\n', dataDir)

%% Create t1 anatomy and t1 class files from freesurfer % Store current directory curdir = pwd();

% This is the path where we will set up the vista session erniePathTemp = fullfile(vistaRootPath, 'local', 'scratch', 'erniePRF'); mkdir(erniePathTemp);

% Navigate cd(erniePathTemp)

% Create t1 anatomy and class file mkdir 3DAnatomy; outfile = fullfile('3DAnatomy', 't1_class.nii.gz'); fillWithCSF = true; alignTo = 'orig.mgz'; fs_ribbon2itk('ernie', outfile, fillWithCSF, alignTo);

% Check that you created a t1 class file (ribbon) and t1 anatomy ls 3DAnatomy

% The command window should show: % t1.nii.gz t1_class.nii.gz

%% Visualize

% Show the volume anatomy, segmentation, and anatomy masked by segmentation ni = niftiRead(fullfile('3DAnatomy', 't1.nii.gz')); t1 = niftiGet(ni, 'data'); ni = niftiRead(fullfile('3DAnatomy', 't1_class.nii.gz')); cl = niftiGet(ni, 'data');

fH = figure('Color','w');

subplot(1,3,1) imagesc(t1(:,:,128), [0 255]); colormap gray; axis image title('Volume anatomy')

subplot(1,3,2) imagesc(cl(:,:,128), [1 6]); axis image title('Class file')

subplot(1,3,3) mask = cl(:,:,128) > 1; imagesc(t1(:,:,128) .* uint8(mask)); axis image title('Masked anatomy')

%% Clean up cd(curdir)

SOURCE END

-->

Clone this wiki locally