source: plugins/save_roi_as_mask.m @ 36

Last change on this file since 36 was 36, checked in by tjniskan, 11 years ago
  • Added option to an2_readfid, an2_data_read and an2_readfidprefs

which allows controlling the output precision. Default is 'double'
(which is more precise), but if you have a very long data changing
this to 'single' will half the memory requirements.

  • Rewrote an2_inputdlg so that it does not depend on Matlab license.
  • Deleted many depricated files.
  • Moved addicon.m under misclib.
  • Added Analyze2 under GNU General Public License (version 2).
  • Added GPL license in license.txt file and added license

notifications in m-files.

M an2_export_gui.m
M analyze2.m
M an2_cellsprintf.m
M an2_getfilefilter.m
M an2_calc_wait.m
D an2_getnicedialoglocation.m
D misclib/uiclear.m
M misclib/spectrsum.m
M misclib/shiftind.m
M misclib/dcm_info.m
D misclib/b1_map.m
A 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
D an2_questerrordlg.m
M an2_readprocpar.m
M an2_fitmaps.m
M an2_read_nifti.m
M an2_data_read.m
A license.txt
M an2_resviewer.m
M an2_maptool.m
M an2_res2table.m
M an2_helpabout.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
D an2_setdefaultbutton.m
M an2_readfid.m
M an2_readfidprefs.m
D addicon.m
M an2_readtab.m
D an2_imaread.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.5 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
83[done,msg]=an2_write_nifti(data,filename,...
84  'VoxelSize',voxelsize,'XYZUnits',xyzunits,...
85  'TimeUnits',timeunits);
86
87if not(done)
88  if not(iscell(msg))
89        msg = {msg};
90  end
91  errordlg({'Could not save file "',filename,'"!',...
92        '',msg{:}},'Error while saving mask!','modal')
93else
94  fprintf(1,'Successfully saved mask to "%s"...\n',filename);
95end
96
Note: See TracBrowser for help on using the repository browser.

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