source: misclib/nifti4dto3d.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.3 KB
Line 
1function nifti4dto3d(infile,outfile)
2% NIFTI4DTO3D - Convert a single 4D NIfTI file into a series of 3D NIfTI
3% files
4%
5% Synopsis:
6%       data = nifti4dto3d(infile,outfile,param1,value1,param2,value2,...)
7%
8% Description:
9%
10% Examples:
11%
12% See also:
13%       
14
15% This function is a part of Analyze 2.0 - A graphical tool for analyzing
16% medical images
17%
18% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
19%
20% Department of Physics, (or Department of Neurobiology)
21% University of Kuopio,
22% P.O. Box 1627,
23% FIN-70211, Kuopio
24% FINLAND
25%
26% This program may be used under the terms of the GNU General Public
27% License version 2.0 as published by the Free Software Foundation
28% and appearing in the file LICENSE.TXT included in the packaging of
29% this program.
30%
31% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
32% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
33
34% Defaults ---------------------------------------
35showWbar = true;
36TR = 0;
37
38if nargin==0
39  % Prompt for a file
40  [fname,fpath,findex] = uigetfile({'*.nii','4D NIfTI Files (*.nii)';...
41        '*.*','All Files (*.*)'},'Select 4D NIfTI file');
42  if isequal(fname,0)
43        % Canceled
44        return
45  end
46  infile = fullfile(fpath,fname);
47end
48
49if nargin<2
50  % Prompt for the outfile
51  [fname,fpath,findex] = uiputfile({'*.nii','4D NIfTI Files (*.nii)';...
52        '*.*','All Files (*.*)'},...
53        'Select folder and file name for 3D NIfTI files',...
54        '3dniftifiles');
55  if isequal(fname,0)
56        % Canceled
57        return
58  end
59  outfile = fullfile(fpath,fname);
60end
61[fp,fn,fe]=fileparts(outfile);
62outfpath = [fp,filesep];
63outfname = fn;
64
65% Read the 4D NIfTI file
66DATA = an2_read_nifti(infile);
67nVol = size(DATA.FTDATA,4);
68
69% Construct the header struct
70FileHeader = DATA.HDR.FileHeader;
71FileHeader.dime.pixdim(5)=0;
72
73
74% Write new 3D NIfTI volumes
75if showWbar
76  wbh=an2_wbar(1/nVol,...
77        sprintf('Writing 3D NIfTI files...1/%d',nVol));
78end
79for ii=1:size(DATA.FTDATA,4)
80 
81  % Generate file name
82  filename = sprintf('%s%s_%04d.nii',outfpath,outfname,ii);
83 
84  % Write NIfTI files...
85  tmp_data.FTDATA = DATA.FTDATA(:,:,:,ii);
86  tmp_data.HDR.FileHeader = FileHeader;
87  an2_write_nifti(tmp_data,filename)
88 
89  if showWbar
90        an2_wbar(ii/nVol,wbh,...
91          sprintf('Writing 3D NIfTI files...%d/%d',ii,nVol))
92  end
93end
94if showWbar
95  close(wbh)
96end
97
98
99
100
Note: See TracBrowser for help on using the repository browser.

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