source: plugins/save_roi_as_mask.m

Last change on this file was 129, checked in by tjniskan, 9 years ago
  • Added plugin for correlation mapping with filtering/other options
  • Added flipping of 3D ROIs in aedes.m
  • Added possibility of changing ROI color (in the ROI -uimenu)
  • Minor fixes/changes here and there...

M misclib/fmri_spm_volumes.m
M misclib/fmri_filter.m
M aedes_fitmaps.m
M aedes.m
M plugins/save_roi_as_mask.m
M plugins/calc_asl_cbf.m
A plugins/fmri_plugins/correlation_mapping.m
M plugins/fmri_plugins/resting_state_fc.m
M plugins/map_plugins/t1_inversion_recovery.m
M aedes_revision.m

File size: 2.6 KB
RevLine 
[23]1function save_roi_as_mask(DATA,ROI,AddInfo)
[39]2% Aedes plugin for saving ROI masks
[23]3
[39]4% This function is a part of Aedes - A graphical tool for analyzing
[36]5% medical images
6%
7% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
8%
[45]9% Department of Physics, Department of Neurobiology
[39]10% University of Kuopio, FINLAND
[36]11%
12% This program may be used under the terms of the GNU General Public
13% License version 2.0 as published by the Free Software Foundation
14% and appearing in the file LICENSE.TXT included in the packaging of
15% this program.
16%
17% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19
[23]20if isempty(ROI)
21  errordlg('ROI(s) not defined. Bailing out!','ROI(s) not defined','modal')
22  return
23end
24
25if AddInfo.isDataMixed
26  % Slice mask
27  CurrentSlice = AddInfo.CurrentSlice;
28  data = ROI(AddInfo.CurrentROI).voxels{CurrentSlice};
29  data = uint8(data);
30else
31  % Volume mask
32  data = ROI(AddInfo.CurrentROI).voxels{1}(:,:,:,AddInfo.CurrentVol);
33  data = uint8(data);
34end
35
36% Get default directory
37try,
[39]38  default_dir = getpref('Aedes','PutDataFileDir');
[23]39catch
40  if isunix
41        default_dir = getenv('HOME');
42  else
43        default_dir = getenv('USERPROFILE');
44  end
45  if not(strcmpi(default_dir(end),filesep))
46        default_dir(end+1)=filesep;
47  end
48end
49
50% Write the NIfTI file
51[fname,fpath,findex]=uiputfile({'*.nii','NIfTI-files (*.nii)';...
52  '*.*','All Files (*.*)'},...
53  'Save As...',[default_dir,'mask.nii']);
54if isequal(fname,0) || isequal(fpath,0)
55  % Canceled
56  return
57end
[129]58setpref('Aedes','PutDataFileDir',fpath);
[23]59[fp,fn,fe]=fileparts([fpath,fname]);
60filename = [fp,filesep,fn,'.nii'];
61
62% If the data is VNMR data, set voxel size to 1mmx1mm
63if strcmpi(DATA{1}.DataFormat,'vnmr')
64  voxelsize = [1 1 DATA{1}.PROCPAR.thk];
65  xyzunits = 'mm';
66  timeunits = 'sec';
67  datatype = 'uint8';
68elseif strncmpi(DATA{1}.DataFormat,'nifti',5)
[37]69%   voxelsize = DATA{1}.HDR.FileHeader.dime.pixdim(2:4);
70%   xyzunits = DATA{1}.HDR.xyzunits;
71%   timeunits = DATA{1}.HDR.timeunits;
72%  datatype = 'uint8';
[23]73else
74  xyzunits = '';
75  timeunits = '';
76  voxelsize = [];
77  datatype = 'uint8';
78end
79 
80% Write data
[37]81if strncmpi(DATA{1}.DataFormat,'nifti',5)
82  DATA{1}.FTDATA=data;
83  datatype = 'uint8';
[80]84  [done,msg]=aedes_write_nifti(DATA{1},filename,...
[37]85        'DataType',datatype);
86else
[80]87  [done,msg]=aedes_write_nifti(data,filename,...
[37]88        'VoxelSize',voxelsize,'XYZUnits',xyzunits,...
89        'TimeUnits',timeunits);
90end
[23]91
92if not(done)
93  if not(iscell(msg))
94        msg = {msg};
95  end
96  errordlg({'Could not save file "',filename,'"!',...
97        '',msg{:}},'Error while saving mask!','modal')
98else
99  fprintf(1,'Successfully saved mask to "%s"...\n',filename);
100end
101
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008