📄 fmr_createamr.m
字号:
function amr = fmr_CreateAMR(hfile, opts)
% FMR::CreateAMR - generate an AMR file
%
% FORMAT: amr = fmr.CreateAMR([opts]);
%
% Input fields:
%
% opts optional struct with settings
% .autoctr auto contrast, default: false
% .invert invert intensities, default: true
% .thresh threshold, default: 0
% .vol 1x1 or 1xN array with volumes to sample, default: 1
%
% Note: as the FMR object is NOT returned, the AMR reference is NOT set!
% Version: v0.7b
% Build: 7083009
% Date: Aug-30 2007, 9:33 AM CEST
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
% argument check
if nargin < 1 || ...
numel(hfile) ~= 1 || ...
~isBVQXfile(hfile, 'fmr')
error( ...
'BVQXfile:BadArgument', ...
'Invalid call to %s.', ...
mfilename ...
);
end
bc = bvqxfile_getcont(hfile.L);
if nargin < 2 || ...
~isstruct(opts) || ...
numel(opts) ~= 1
opts = struct;
end
if ~isfield(opts, 'autoctr') || ...
numel(opts.autoctr) ~= 1 || ...
~islogical(opts.autoctr)
opts.autoctr = false;
end
if ~isfield(opts, 'dim') || ...
numel(opts.dim) ~= 2 || ...
~isa(opts.dim, 'double') || ...
any(isnan(opts.dim) | opts.dim < 64 | opts.dim > 512 | ...
opts.dim ~= fix(opts.dim))
opts.dim = [256, 256];
else
opts.dim = 2 * round(opts.dim(:)' / 2);
end
if ~isfield(opts, 'invert') || ...
numel(opts.invert) ~= 1 || ...
~islogical(opts.invert)
opts.invert = true;
end
if ~isfield(opts, 'thresh') || ...
numel(opts.thresh) ~= 1 || ...
~isa(opts.thresh, 'double') || ...
isnan(opts.thresh) || ...
opts.thresh < 0 || ...
opts.thresh > 32767
opts.thresh = uint16(0);
else
opts.thresh = uint16(floor(opts.thresh));
end
if ~isfield(opts, 'vol') || ...
isempty(opts.vol) || ...
~isa(opts.vol, 'double') || ...
any(isnan(opts.vol(:)) | opts.vol(:) < 1 | ...
opts.vol(:) > 512 | bc.NrOfVolumes | ...
opts.vol(:) ~= fix(opts.vol(:)))
opts.vol = 1;
else
opts.vols = unique(opts.vol(:)');
end
% make sure data is loaded
try
if isempty(bc.Slice) || ...
~isstruct(bc.Slice) || ...
~isfield(bc.Slice, 'STCData')
fmr_LoadSTC(hfile);
bc = bvqxfile_getcont(hfile.L);
end
catch
error( ...
'BVQXfile:InternalError', ...
'Error loading slice data.' ...
);
end
% get FMR resolution
dmx = bc.ResolutionX;
dmy = bc.ResolutionY;
dmz = bc.NrOfSlices;
% build output
amr = BVQXfile('new:amr');
amrc = bvqxfile_getcont(amr.L);
slc = amrc.Slice(1);
% init slice object
slc.BITMAPFILEHEADER.bfSize = 1078 + prod(opts.dim);
slc.BITMAPINFOHEADER.bfWidth = opts.dim(2);
slc.BITMAPINFOHEADER.bfHeight = opts.dim(1);
slc.BITMAPINFOHEADER.biImageSize = prod(opts.dim);
slc(2:dmz) = slc(1);
% compute interpolation matrix
[s1, s2] = ndgrid( ...
1 + 0:(opts.dim(1) - 1) / (opts.dim(1) / dmy), ...
1 + 0:(opts.dim(2) - 1) / (opts.dim(2) / dmx));
% build data
amrd = zeros([opts.dim, dmz]);
% interpolate data
for sc = 1:dimz
% depends on file version
if bc.FileVersion < 5 || ...
bc.DataStorageFormat == 1
amrd(:, :, sc) = interpn(mean( ...
bc.Slice(sc).STCData(:, :, opts.vol), 3), s1, s2);
elseif bc.DataStorageFormat == 2
amrd(:, :, sc) = interpn(mean( ...
bc.Slice.STCData(:, :, opts.vol, sc), 3), s1, s2);
else
BVQXfile(0, 'clearobj', amr.L);
error( ...
'BVQXfile:InvalidObject', ...
'Unsupported DataStorageFormat.' ...
);
end
end
% contrast
% iterate again for storage
for sc = 1:dmz
% store in AMR slice
slc(sc).AMRData = uint8(round(amrd(:, :, sc)));
end
% fill object
amrc.NrOfSlices = dmz;
amrc.Slice = slc;
bvqxfile_setcont(amr.L, amrc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -