📄 vtc_reframe.m
字号:
function hfile = vtc_Reframe(hfile, bbox)
% VTC::Reframe - reframe a VTC
%
% FORMAT: [vtc] = vtc.Reframe(bbox)
%
% Input fields:
%
% bbox 2x3 bounding box
% Version: v0.7b
% Build: 7083012
% Date: Aug-30 2007, 12:51 PM CEST
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
% argument check
if nargin < 2 || ...
numel(hfile) ~= 1 || ...
~isBVQXfile(hfile, 'vtc') || ...
~isa(bbox, 'double') || ...
length(size(bbox)) ~= 2 || ...
numel(bbox) ~= 6 || ...
any(isinf(bbox(:)) | isnan(bbox(:)))
error( ...
'BVQXfile:BadArgument', ...
'Invalid call to %s.', ...
mfilename ...
);
end
% get object reference
bc = bvqxfile_getcont(hfile.L);
% check bbox size
if size(bbox, 2) == 3
bbox = bbox';
end
% get current array size
oOffsetX = bc.XStart;
oOffsetY = bc.YStart;
oOffsetZ = bc.ZStart;
oDimX = size(bc.VTCData, 2);
oDimY = size(bc.VTCData, 3);
oDimZ = size(bc.VTCData, 4);
oRes = bc.Resolution;
% try to get new array size
nOffsetX = bbox(1);
nOffsetY = bbox(2);
nOffsetZ = bbox(3);
nDimX = round((bbox(4) - nOffsetX) / oRes);
nDimY = round((bbox(5) - nOffsetY) / oRes);
nDimZ = round((bbox(6) - nOffsetZ) / oRes);
% check new dims
if any([nDimX, nDimY, nDimZ] < 0)
error( ...
'BVQXfile:BadArgument', ...
'Invalid bounding box.' ...
);
end
nVTC = uint16(0);
try
nVTC(size(bc.VTCData, 1), nDimX, nDimY, nDimZ) = nVTC(1);
catch
error( ...
'BVQXfile:InternalError', ...
'Invalid dimensions for reframing.' ...
);
end
% decide on source/target indexing...
sfx = max(1, round(1 + (nOffsetX - oOffsetX) / oRes));
tfx = max(1, round(1 + (oOffsetX - nOffsetX) / oRes));
stx = min(oDimX, nDimX + round((nOffsetX - oOffsetX) / oRes));
ttx = tfx + stx - sfx;
sfy = max(1, round(1 + (nOffsetY - oOffsetY) / oRes));
tfy = max(1, round(1 + (oOffsetY - nOffsetY) / oRes));
sty = min(oDimY, nDimY + round((nOffsetY - oOffsetY) / oRes));
tty = tfy + sty - sfy;
sfz = max(1, round(1 + (nOffsetZ - oOffsetZ) / oRes));
tfz = max(1, round(1 + (oOffsetZ - nOffsetZ) / oRes));
stz = min(oDimZ, nDimZ + round((nOffsetZ - oOffsetZ) / oRes));
ttz = tfz + stz - sfz;
% try data copy
try
nVTC(1:end, tfx:ttx, tfy:tty, tfz:ttz) = ...
bc.VTCData(1:end, sfx:stx, sfy:sty, sfz:stz);
catch
error( ...
'BVQXfile:InternalError', ...
'Error calculating copy from/to indices.' ...
);
end
% overwrite VMRData in hfile
bc.VTCData = nVTC;
% set fields
bc.XStart = nOffsetX;
bc.YStart = nOffsetY;
bc.ZStart = nOffsetZ;
bc.XEnd = nOffsetX + oRes * size(nVTC, 2);
bc.YEnd = nOffsetY + oRes * size(nVTC, 3);
bc.ZEnd = nOffsetZ + oRes * size(nVTC, 4);
% put back into storage
bvqxfile_setcont(hfile.L, bc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -