source: plugins/save_roi_as_mask.m @ 45

Last change on this file since 45 was 45, checked in by tjniskan, 11 years ago
  • Changed a small thing in license notices

M an2_export_gui.m
M an2_cellsprintf.m
M an2_getfilefilter.m
M an2_calc_wait.m
M an2_smiswrite.m
M misclib/spectrsum.m
M misclib/shiftind.m
M misclib/nifti4dto3d.m
M misclib/nifti3dto4d.m
M misclib/dcm_info.m
M misclib/addicon.m
M misclib/makelcmraw.m
M an2_check_file_exist.m
M an2_iseven.m
M an2_cellwrite.m
M an2_wbar.m
M an2_rot3d.m
M an2_readfdf.m
M an2_revision.m
M an2_viewprocpar.m
M an2_checkcthdr.m
M an2_readprocpar.m
M an2_fitmaps.m
M an2_read_nifti.m
M an2_data_read.m
M an2_smisread.m
M an2_resviewer.m
M an2_maptool.m
M aedes.m
M an2_helpabout.m
M an2_res2table.m
M an2_copy_roi.m
M plugins/save_roi_as_mask.m
M plugins/write_difference_images.m
M plugins/plot_profile.m
M plugins/calculate_t2_map.m
M plugins/calculate_t1r_map.m
M plugins/view_kspace.m
M plugins/copy_data_to_workspace.m
M plugins/take_snapshot.m
M an2_inputdlg.m
M an2_roi_copy_gui.m
M an2_readctdata.m
M an2_readfid.m
M an2_readfidprefs.m
M an2_readtab.m
M an2_check_updates.m
M an2_killfigs.m
M an2_roi_stats.m
M an2_saveres.m
M an2_rotateflip.m
M an2_juigetfiles.m
M an2_gui_defaults.m
M an2_editstack.m
M an2_errordump.m
M an2_update.m
M an2_write_nifti.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]=an2_write_nifti(DATA{1},filename,...
84        'DataType',datatype);
85else
86  [done,msg]=an2_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