Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
%% ---------- Atlas Normalisation from Native to Allen space using DARTEL------------ %%%%
addpath(genpath('~/code/matlab/Atlas_Norm_Dartel_analysis'));
%% Prerequisites to run DARTEL toolbox.
% manual alignment
%%% bet images are already aligned.
% change vox size of AVGT & input images
% bet images already have the same vox sizes.
% % execute reslice job.
% matlabbatch{1}.spm.spatial.coreg.write.ref = {'/home/tchaudhuri/data/Tan_Dartel_Playground/AVGT_x10.nii,1'};
%
% matlabbatch{1}.spm.spatial.coreg.write.source = {
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0001x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0003x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0005x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0007x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0009x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0011x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0013x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0015x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0017x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0023x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0025x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0029x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0031x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0033x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0035x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0037x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0039x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0041x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/bet_sub-0043x10__T1w.nii,1'
% };
%
% matlabbatch{1}.spm.spatial.coreg.write.roptions.interp = 4;
% matlabbatch{1}.spm.spatial.coreg.write.roptions.wrap = [0 0 0];
% matlabbatch{1}.spm.spatial.coreg.write.roptions.mask = 0;
% matlabbatch{1}.spm.spatial.coreg.write.roptions.prefix = 'r';
%
% spm('defaults', 'FMRI');
% spm_jobman('run',matlabbatch);
%% 1. Manual Alignment.
%%% Align images manually using the display option in SPM. Do not use the
% automated version of this step from ANT-X.
%% 2. Segmentation using allen space tpms.
% Segmentation of aligned images. Prerequisite of this is to ensure that
% the input image and the templates have the same resolution. Change voxel
% size using Micha's script.
% addpath(genpath('/home/tchaudhuri/toolboxes/spm12'));
% spm_jobman('initcfg');
% data_dir = input('Enter fullpath of data folder: ');
% cd(data_dir);
% segment_job;
% matlabbatch{1}.spm.spatial.preproc.warp.vox = 0.7;
% spm_preproc_run(matlabbatch{1}.spm.spatial.preproc,'run')
% clear matlabbatch
%
% matlabbatch{1}.spm.spatial.preproc.channel.vols = {
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0001x10__T1w.nii,1'
% };
% % '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0003x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0005x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0007x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0009x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0011x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0013x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0015x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0017x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0023x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0025x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0029x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0031x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0033x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0035x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0037x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0039x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0041x10__T1w.nii,1'
% '/home/tchaudhuri/data/Tan_Dartel_Playground/rbet_sub-0043x10__T1w.nii,1'
% };
% matlabbatch{1}.spm.spatial.preproc.channel.biasreg = 1.0000e-03;
% matlabbatch{1}.spm.spatial.preproc.channel.biasfwhm = 60;
% matlabbatch{1}.spm.spatial.preproc.channel.write = [0 1];
%
% matlabbatch{1}.spm.spatial.preproc.tissue(1).tpm={'/home/tchaudhuri/data/Tan_Dartel_Playground/_b1grey.nii,1'};
% matlabbatch{1}.spm.spatial.preproc.tissue(2).tpm={'/home/tchaudhuri/data/Tan_Dartel_Playground/_b2white.nii,1'};
% matlabbatch{1}.spm.spatial.preproc.tissue(3).tpm={'/home/tchaudhuri/data/Tan_Dartel_Playground/_b3csf.nii,1'};
% matlabbatch{1}.spm.spatial.preproc.tissue(1).ngaus=1;
% matlabbatch{1}.spm.spatial.preproc.tissue(2).ngaus=1;
% matlabbatch{1}.spm.spatial.preproc.tissue(3).ngaus=2;
% matlabbatch{1}.spm.spatial.preproc.tissue(1).native=[1 1];
% matlabbatch{1}.spm.spatial.preproc.tissue(2).native=[1 1];
% matlabbatch{1}.spm.spatial.preproc.tissue(3).native=[1 1];
% matlabbatch{1}.spm.spatial.preproc.tissue(1).warped=[0 1];
% matlabbatch{1}.spm.spatial.preproc.tissue(2).warped=[0 1];
% matlabbatch{1}.spm.spatial.preproc.tissue(3).warped=[0 1];
%
% matlabbatch{1}.spm.spatial.preproc.warp.mrf = 1;
% matlabbatch{1}.spm.spatial.preproc.warp.cleanup = 1;
% matlabbatch{1}.spm.spatial.preproc.warp.reg = [0 0.0010 0.5000 0.0500 0.2000];
% matlabbatch{1}.spm.spatial.preproc.warp.affreg = '';
% matlabbatch{1}.spm.spatial.preproc.warp.fwhm = 0;
% matlabbatch{1}.spm.spatial.preproc.warp.samp = 3;
% matlabbatch{1}.spm.spatial.preproc.warp.write = [0 0];
%
% matlabbatch{1}.spm.spatial.preproc.warp.vox = 0.7;
%% 2. Segmentation using spmmouse tpms. - the job below already produces dartel imported images (rc.*), so a separate import step is not needed.
addpath(genpath('/home/tchaudhuri/toolboxes/spm12'));
spm_jobman('initcfg');
clear matlabbatch
segment_en_spmmouse_job;
spm_preproc_run(matlabbatch{1}.spm.spatial.preproc,'run')
%% 4. Run Dartel (create templates from imported segments) - run only once. For the next run, change template name.
% create_templates_job;
% create_templates;
%% 5. Run Dartel (using existing templates) on affine transformed images (rc1,rc2,...)
% dartel_with_existing_templates_job;
% dartel_with_existing_templates;
%% 6. Create Normalised images - create warped images using flow fields (u-files) to get final
% normalised output image.
% dartel_create_warped_job;
% dartel_create_warped;
%% 7. Evaluating Results
% --- Qualitative --- %
% Check reg with template image and warped image.
% template image = Template_6.nii
% warped image = wrc1
% --- Quantitative --- % [not so sure]
% Convert 4D volume file into a series of 3D volumes.
% convert_2_3D_job;
% convert_2_3D;
ref = niftiread('Template_6_00001.nii');
A = niftiread('wrc1bet_sub-0001x10__T1w.nii');
[ssimval, ssimmap] = ssim(A,ref);