source: plugins/save_roi_as_mask.m @ 37

Last change on this file since 37 was 37, checked in by tjniskan, 11 years ago
  • Renamed analyze2.m to aedes.m
  • Changed all references to "Analyze2" -> "Aedes" (hopefully I didn't

break anything...)

  • Added some nifti-tools to misclib
  • Fixed bug in an2_readfid.m that occurred when reading EPI-data

(thanks Teemu)

M an2_export_gui.m
D analyze2.m
M an2_getfilefilter.m
M an2_calc_wait.m
A misclib/nifti4dto3d.m
A misclib/nifti3dto4d.m
A misclib/filter_fmri_data.m
M misclib/dcm_info.m
M an2_cellwrite.m
M an2_revision.m
M startup.m
M an2_readprocpar.m
M an2_fitmaps.m
M an2_read_nifti.m
M an2_data_read.m
D about_analyze2.png
M an2_resviewer.m
M an2_maptool.m
A aedes.m
M an2_helpabout.m
M plugins/save_roi_as_mask.m
M plugins/calculate_t2_map.m
M an2_inputdlg.m
M an2_readctdata.m
M an2_readfid.m
M an2_readfidprefs.m
M an2_readtab.m
M an2_check_updates.m
A about_aedes.png
M an2_saveres.m
M an2_editstack.m
M an2_errordump.m
M an2_update.m
M an2_write_nifti.m

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

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