Code covered by the BSD License
-
rri_orient_ui(varargin)
Return orientation of the current image:
-
rri_select_file(varargin)
-
view_nii(varargin)
-
affine(old_img, old_M, new_el...
Using 2D or 3D affine matrix to rotate, translate, scale, reflect and
-
bipolar(M, lo, hi, contrast)
BIPOLAR returns an M-by-3 matrix containing a blue-red colormap, in
-
bresenham_line3d(P1, P2, prec...
Generate X Y Z coordinates of a 3D Bresenham's line between
-
collapse_nii_scan(scan_patter...
Collapse multiple single-scan NIFTI files into a multiple-scan NIFTI file
-
expand_nii_scan(filename, img...
Expand a multiple-scan NIFTI file into multiple single-scan NIFTI files
-
extra_nii_hdr(hdr)
Decode extra NIFTI header information into hdr.extra
-
flip_lr(original_fn, flipped_...
When you load any ANALYZE or NIfTI file with 'load_nii.m', and view
-
get_nii_frame(fileprefix)
Return time frame of a NIFTI dataset. Support both *.nii and
-
load_nii(filename, img_idx, d...
-
load_nii_ext(fileprefix)
Load NIFTI header extension after its header is loaded using load_nii_hdr.
-
load_nii_hdr(fileprefix)
internal function
-
load_nii_hdr(fileprefix, mach...
internal function
-
load_nii_hdr(fileprefix, mach...
internal function
-
load_nii_img(hdr,filetype,fil...
internal function
-
load_untouch_header_only(file...
Load NIfTI / Analyze header without applying any appropriate affine
-
load_untouch_nii(filename, im...
Load NIFTI or ANALYZE dataset, but not applying any appropriate affine
-
load_untouch_nii_img(hdr,file...
internal function
-
make_ana(varargin)
Make ANALYZE 7.5 data structure specified by a 3D or 4D matrix.
-
make_nii(varargin)
Make NIfTI structure specified by an N-D matrix. Usually, N is 3 for
-
mat_into_hdr(files)
MAT_INTO_HDR The old versions of SPM (any version before SPM5) store
-
reslice_nii(old_fn, new_fn, v...
The basic application of the 'reslice_nii.m' program is to perform
-
rri_file_menu(action, varargi...
Imbed a file menu to any figure. If file menu exist, it will append
-
rri_orient(nii, varargin)
Convert image of different orientations to standard Analyze orientation
-
rri_xhair(varargin)
rri_xhair: create a pair of full_cross_hair at point [x y] in
-
rri_zoom_menu(fig)
Imbed a zoom menu to any figure.
-
save_nii(nii, fileprefix, old...
-
save_nii_ext(ext, fid)
Save NIFTI header extension.
-
save_nii_hdr(hdr, fid)
internal function
-
save_nii_hdr(hdr, fid)
internal function
-
save_nii_hdr(hdr, fid)
internal function
-
save_untouch_nii(nii, filenam...
Save NIFTI or ANALYZE dataset that is loaded by "load_untouch_nii.m".
-
save_untouch_slice(slice, fil...
Save back to the back to the original image a portion of slices that
-
unxform_nii(nii, inblock)
Undo the flipping and rotations performed by xform_nii; spit back only
-
verify_nii_ext(ext)
Verify NIFTI header extension to make sure that each extension section
-
view_nii_menu(fig, varargin)
Imbed Zoom, Interp, and Info menu to view_nii window.
-
xform_nii(nii, tolerance, pre...
internal function
-
View all files
from
Tools for NIfTI and ANALYZE image
by Jimmy Shen
Load, save, make, reslice, view (and edit) both NIfTI and ANALYZE data on any platform
|
| rri_orient(nii, varargin)
|
% Convert image of different orientations to standard Analyze orientation
%
% Usage: nii = rri_orient(nii);
% Jimmy Shen (jimmy@rotman-baycrest.on.ca), 26-APR-04
%___________________________________________________________________
function [nii, orient, pattern] = rri_orient(nii, varargin)
if nargin > 1
pattern = varargin{1};
else
pattern = [];
end
orient = [1 2 3];
dim = double(nii.hdr.dime.dim([2:4]));
if ~isempty(pattern) & ~isequal(length(pattern), prod(dim))
return;
end
% get orient of the current image
%
orient = rri_orient_ui;
pause(.1);
% no need for conversion
%
if isequal(orient, [1 2 3])
return;
end
if isempty(pattern)
pattern = 1:prod(dim);
end
pattern = reshape(pattern, dim);
img = nii.img;
% calculate after flip orient
%
rot_orient = mod(orient + 2, 3) + 1;
% do flip:
%
flip_orient = orient - rot_orient;
for i = 1:3
if flip_orient(i)
pattern = flipdim(pattern, i);
img = flipdim(img, i);
end
end
% get index of orient (do inverse)
%
[tmp rot_orient] = sort(rot_orient);
% do rotation:
%
pattern = permute(pattern, rot_orient);
img = permute(img, [rot_orient 4 5 6]);
% rotate resolution, or 'dim'
%
new_dim = nii.hdr.dime.dim([2:4]);
new_dim = new_dim(rot_orient);
nii.hdr.dime.dim([2:4]) = new_dim;
% rotate voxel_size, or 'pixdim'
%
tmp = nii.hdr.dime.pixdim([2:4]);
tmp = tmp(rot_orient);
nii.hdr.dime.pixdim([2:4]) = tmp;
% re-calculate originator
%
tmp = nii.hdr.hist.originator([1:3]);
tmp = tmp(rot_orient);
flip_orient = flip_orient(rot_orient);
for i = 1:3
if flip_orient(i) & ~isequal(double(tmp(i)), 0)
tmp(i) = int16(double(new_dim(i)) - double(tmp(i)) + 1);
end
end
nii.hdr.hist.originator([1:3]) = tmp;
nii.img = img;
pattern = pattern(:);
return; % rri_orient
|
|
Contact us at files@mathworks.com