📄 importvtcfromanalyze.m
字号:
function vtc = importvtcfromanalyze(imgs, bbox, res, imeth)
% importvtcfromanalyze - import a VTC from Analzye files
%
% FORMAT: vtc = importvtcfromanalyze(imgs [, bbox [, res [, imeth]])
%
% Input fields:
%
% imgs cell array with HDR filenames for BVQXfile
% bbox optional 2x3 bounding box (default: auto detect)
% res optional resolution (default: Analyze resolution
% if 3 or 2, otherwise take best guess)
% imeth interpolation, {'linear'}, 'cubic', 'spline'
%
% Output fields:
%
% vtc created VTC object
% Version: v0.7b
% Build: 7090522
% Date: Sep-05 2007, 10:19 PM CEST
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
% argument check
if nargin < 1 || ...
~iscell(imgs) || ...
numel(imgs) < 3 || ...
~ischar(imgs{1}) || ...
isempty(imgs{1}) || ...
exist(imgs{1}(:)', 'file') ~= 2
error( ...
'BVQXtools:BadArgument', ...
'Bad input argument.' ...
);
end
imgs = imgs(:);
nimg = numel(imgs);
himg = cell(1, nimg);
vimg = zeros(20, nimg);
try
pbar = BVQXprogress;
BVQXprogress(pbar, 'setposition', [80, 200, 640, 36]);
BVQXprogress(pbar, 'settitle', 'Converting Analyze to VTC...');
BVQXprogress(pbar, 0, 'Checking HDRs...', 'visible', 0, 8 * nimg);
catch
pbar = [];
end
try
for ic = 1:nimg
if ~ischar(imgs{ic}) || ...
isempty(imgs{ic})
error('BAD_IMAGENAME');
end
himg{ic} = BVQXfile(imgs{ic});
if numel(himg{ic}) ~= 1 ||...
~isBVQXfile(himg{ic}, 'hdr')
error('BAD_IMAGECONT');
end
icf = himg{ic}.CoordinateFrame;
vimg(:, ic) = [icf.Trf(:); icf.Dimensions(:)];
if ~isempty(pbar)
BVQXprogress(pbar, ic);
end
end
if any(any(diff(vimg, 1, 2)))
error( ...
'BVQXtools:BadArgument', ...
'Spatial orientation/dimensions mismatch between images.' ...
);
end
catch
clearbvqxobjects(himg);
if ~isempty(pbar)
closebar(pbar);
end
error( ...
'BVQXtools:BadArgument', ...
'Error loading image %d.', ...
ic ...
);
end
bb = himg{1}.BoundingBox;
sfn = himg{1}.FilenameOnDisk;
if nargin < 2 || ...
~isa(bbox, 'double') || ...
~isequal(size(bbox), [2, 3]) || ...
any(isnan(bbox(:)) | bbox(:) < 0 | bbox(:) > 255)
bbox = bb.BBox;
else
bbox = round(bbox);
end
if nargin < 3 || ...
~isa(res, 'double') || ...
numel(res) ~= 1 || ...
~any((1:12) == res)
if all(bb.ResXYZ == bb.ResXYZ(1))
if any((1:12) == bb.ResXYZ(1))
res = bb.ResXYZ(1);
imeth = 'nearest';
else
res = ceil(bb.ResXYZ(1) / 2);
end
else
res = ceil(min(bb.ResXYZ) / 2);
end
end
if nargin < 4 || ...
~ischar(imeth) || ...
~any(strcmpi(imeth(:)', {'cubic', 'linear', 'nearest', 'spline'}))
imeth = 'linear';
else
imeth = lower(imeth(:)');
end
% build coordinate indices for sampling
xs = 0.5 * res + (bbox(1, 1):res:bbox(2, 1));
ys = 0.5 * res + (bbox(1, 2):res:bbox(2, 2));
zs = 0.5 * res + (bbox(1, 3):res:bbox(2, 3));
% create VTC data
vtd = uint16([]);
vtd(nimg, numel(xs), numel(ys), numel(zs)) = 0;
vts = size(vtd);
% guess scaling
himg{1}.VoxelData = himg{1}.VoxelData(:, :, :);
vds = single(himg{1}.VoxelData);
vdm = max(vds(:));
if vdm > 16384
vdf = single(16384 / vdm);
else
vdf = [];
end
% interpolation
[xs, ys, zs] = ndgrid(single(xs), single(ys), single(zs));
xs = xs(:);
ys = ys(:);
zs = zs(:);
c = 128 - [zs, xs, ys];
if ~isempty(pbar)
BVQXprogress(pbar, nimg, 'Sampling images...');
end
for ic = 1:nimg
try
himg{ic}.VoxelData = himg{ic}.VoxelData(:, :, :);
hy = reshape(himg{ic}.SampleCoords(c, 1, imeth, 'tal'), [1, vts(2:4)]);
himg{ic}.ClearObject;
himg{ic} = [];
if ~isempty(vdf)
hy = vdf * hy;
end
if ~isempty(pbar)
BVQXprogress(pbar, nimg + 7 * ic);
end
vtd(ic, :, :, :) = hy;
catch
if ~isempty(pbar)
closebar(pbar);
end
error( ...
'BVQXtools:InternalError', ...
'Error sampling data of volume %d.', ...
ic ...
),
end
end
% create VTC
vtc = bless(BVQXfile('new:vtc'), 1);
vtc.NameOfSourceFMR = sfn;
vtc.Resolution = res;
vtc.XStart = bbox(1, 1);
vtc.XEnd = bbox(1, 1) + res * vts(2);
vtc.YStart = bbox(1, 2);
vtc.YEnd = bbox(1, 2) + res * vts(3);
vtc.ZStart = bbox(1, 3);
vtc.ZEnd = bbox(1, 3) + res * vts(4);
vtc.VTCData = vtd;
vtd = [];
clear vtd;
vtc.NrOfVolumes = size(vtc.VTCData, 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -