source: plugins/save_roi_as_mask.m @ 23

Last change on this file since 23 was 23, checked in by tjniskan, 12 years ago
  • Fixed a few linux specific bugs
  • Added uicomponent.m for using java widgets
  • The waitbar (an2_wbar.m) now uses java (jProgressBar)
  • Added a plugin "save_roi_as_mask.m" that can be used to

create masks for SPM and FSL (fMRI analysis)

  • Fixed a minor bug in the writing nifti files
  • Added support for 3D fast spin-echo sequences in an2_readfid.m

M analyze2.m
M an2_wbar.m
M an2_revision.m
A uicomponent.m
M an2_read_nifti.m
A plugins/save_roi_as_mask.m
M an2_readfid.m
M an2_juigetfiles.m
M an2_write_nifti.m

File size: 1.8 KB
Line 
1function save_roi_as_mask(DATA,ROI,AddInfo)
2
3if isempty(ROI)
4  errordlg('ROI(s) not defined. Bailing out!','ROI(s) not defined','modal')
5  return
6end
7
8if AddInfo.isDataMixed
9  % Slice mask
10  CurrentSlice = AddInfo.CurrentSlice;
11  data = ROI(AddInfo.CurrentROI).voxels{CurrentSlice};
12  data = uint8(data);
13else
14  % Volume mask
15  data = ROI(AddInfo.CurrentROI).voxels{1}(:,:,:,AddInfo.CurrentVol);
16  data = uint8(data);
17end
18
19% Get default directory
20try,
21  default_dir = getpref('Analyze2','PutDataFileDir');
22catch
23  if isunix
24        default_dir = getenv('HOME');
25  else
26        default_dir = getenv('USERPROFILE');
27  end
28  if not(strcmpi(default_dir(end),filesep))
29        default_dir(end+1)=filesep;
30  end
31end
32
33% Write the NIfTI file
34[fname,fpath,findex]=uiputfile({'*.nii','NIfTI-files (*.nii)';...
35  '*.*','All Files (*.*)'},...
36  'Save As...',[default_dir,'mask.nii']);
37if isequal(fname,0) || isequal(fpath,0)
38  % Canceled
39  return
40end
41[fp,fn,fe]=fileparts([fpath,fname]);
42filename = [fp,filesep,fn,'.nii'];
43
44% If the data is VNMR data, set voxel size to 1mmx1mm
45if strcmpi(DATA{1}.DataFormat,'vnmr')
46  voxelsize = [1 1 DATA{1}.PROCPAR.thk];
47  xyzunits = 'mm';
48  timeunits = 'sec';
49  datatype = 'uint8';
50elseif strncmpi(DATA{1}.DataFormat,'nifti',5)
51  voxelsize = DATA{1}.HDR.FileHeader.dime.pixdim(2:4);
52  xyzunits = DATA{1}.HDR.xyzunits;
53  timeunits = DATA{1}.HDR.timeunits;
54  datatype = 'uint8';
55else
56  xyzunits = '';
57  timeunits = '';
58  voxelsize = [];
59  datatype = 'uint8';
60end
61 
62% Write data
63[done,msg]=an2_write_nifti(data,filename,...
64  'VoxelSize',voxelsize,'XYZUnits',xyzunits,...
65  'TimeUnits',timeunits);
66
67if not(done)
68  if not(iscell(msg))
69        msg = {msg};
70  end
71  errordlg({'Could not save file "',filename,'"!',...
72        '',msg{:}},'Error while saving mask!','modal')
73else
74  fprintf(1,'Successfully saved mask to "%s"...\n',filename);
75end
76
Note: See TracBrowser for help on using the repository browser.

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