source: plugins/save_roi_as_mask.m @ 80

Last change on this file since 80 was 80, checked in by tjniskan, 10 years ago
  • Changed the historical "an2_" prefix to "aedes_" in all files. NOTE:

Any script or function relying to Aedes functions will be broken
because of this. Just do a search/replace from "an2_" to "aedes_" in
your files and all should be well...

  • Changed the name of an2_readtab.m to a more informative

aedes_readphasetable.m

File size: 2.6 KB
Line 
1function save_roi_as_mask(DATA,ROI,AddInfo)
2% Aedes plugin for saving ROI masks
3
4% This function is a part of Aedes - A graphical tool for analyzing
5% medical images
6%
7% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
8%
9% Department of Physics, Department of Neurobiology
10% University of Kuopio, FINLAND
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
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,
38  default_dir = getpref('Aedes','PutDataFileDir');
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
58[fp,fn,fe]=fileparts([fpath,fname]);
59filename = [fp,filesep,fn,'.nii'];
60
61% If the data is VNMR data, set voxel size to 1mmx1mm
62if strcmpi(DATA{1}.DataFormat,'vnmr')
63  voxelsize = [1 1 DATA{1}.PROCPAR.thk];
64  xyzunits = 'mm';
65  timeunits = 'sec';
66  datatype = 'uint8';
67elseif strncmpi(DATA{1}.DataFormat,'nifti',5)
68%   voxelsize = DATA{1}.HDR.FileHeader.dime.pixdim(2:4);
69%   xyzunits = DATA{1}.HDR.xyzunits;
70%   timeunits = DATA{1}.HDR.timeunits;
71%  datatype = 'uint8';
72else
73  xyzunits = '';
74  timeunits = '';
75  voxelsize = [];
76  datatype = 'uint8';
77end
78 
79% Write data
80if strncmpi(DATA{1}.DataFormat,'nifti',5)
81  DATA{1}.FTDATA=data;
82  datatype = 'uint8';
83  [done,msg]=aedes_write_nifti(DATA{1},filename,...
84        'DataType',datatype);
85else
86  [done,msg]=aedes_write_nifti(data,filename,...
87        'VoxelSize',voxelsize,'XYZUnits',xyzunits,...
88        'TimeUnits',timeunits);
89end
90
91if not(done)
92  if not(iscell(msg))
93        msg = {msg};
94  end
95  errordlg({'Could not save file "',filename,'"!',...
96        '',msg{:}},'Error while saving mask!','modal')
97else
98  fprintf(1,'Successfully saved mask to "%s"...\n',filename);
99end
100
Note: See TracBrowser for help on using the repository browser.

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