source: misclib/nifti4dto3d.m @ 40

Last change on this file since 40 was 40, checked in by tjniskan, 11 years ago
  • Rewrote the handling of the old SUR and MRI formats

(an2_smiswrite.m,an2_smisread.m). Consider this as "legacy support"...

  • Removed depricated functions write_mri.m, an2_surread.m and

an2_mriread.m

  • Now (hopefully) the name change is complete and all the license

issues are resolved...

A 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_revision.m
D write_mri.m
M an2_data_read.m
D an2_surread.m
A an2_smisread.m
M aedes.m
D an2_mriread.m

File size: 2.2 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 Aedes - 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, FINLAND
22%
23% This program may be used under the terms of the GNU General Public
24% License version 2.0 as published by the Free Software Foundation
25% and appearing in the file LICENSE.TXT included in the packaging of
26% this program.
27%
28% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30
31% Defaults ---------------------------------------
32showWbar = true;
33TR = 0;
34
35if nargin==0
36  % Prompt for a file
37  [fname,fpath,findex] = uigetfile({'*.nii','4D NIfTI Files (*.nii)';...
38        '*.*','All Files (*.*)'},'Select 4D NIfTI file');
39  if isequal(fname,0)
40        % Canceled
41        return
42  end
43  infile = fullfile(fpath,fname);
44end
45
46if nargin<2
47  % Prompt for the outfile
48  [fname,fpath,findex] = uiputfile({'*.nii','4D NIfTI Files (*.nii)';...
49        '*.*','All Files (*.*)'},...
50        'Select folder and file name for 3D NIfTI files',...
51        '3dniftifiles');
52  if isequal(fname,0)
53        % Canceled
54        return
55  end
56  outfile = fullfile(fpath,fname);
57end
58[fp,fn,fe]=fileparts(outfile);
59outfpath = [fp,filesep];
60outfname = fn;
61
62% Read the 4D NIfTI file
63DATA = an2_read_nifti(infile);
64nVol = size(DATA.FTDATA,4);
65
66% Construct the header struct
67FileHeader = DATA.HDR.FileHeader;
68FileHeader.dime.pixdim(5)=0;
69
70
71% Write new 3D NIfTI volumes
72if showWbar
73  wbh=an2_wbar(1/nVol,...
74        sprintf('Writing 3D NIfTI files...1/%d',nVol));
75end
76for ii=1:size(DATA.FTDATA,4)
77 
78  % Generate file name
79  filename = sprintf('%s%s_%04d.nii',outfpath,outfname,ii);
80 
81  % Write NIfTI files...
82  tmp_data.FTDATA = DATA.FTDATA(:,:,:,ii);
83  tmp_data.HDR.FileHeader = FileHeader;
84  an2_write_nifti(tmp_data,filename)
85 
86  if showWbar
87        an2_wbar(ii/nVol,wbh,...
88          sprintf('Writing 3D NIfTI files...%d/%d',ii,nVol))
89  end
90end
91if showWbar
92  close(wbh)
93end
94
95
96
97
Note: See TracBrowser for help on using the repository browser.

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