source: misclib/nifti4dto3d.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.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, 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