Newer
Older
function output=gtPlaceSubVolume(output, input, shift)
% output=gtPlaceSubVolume(output, input, shift)
% ~analogous to gtPlaceSubImage
% places the input volume in the output vol, with the origin of the input
% volume at point defined by shift=[y x z] in the output volume. Any part of the
% input volume falling outside of the output volume is cropped. Origin
% can contain negative coordinates, again anything outside the output
% volume is cropped.
% so... shift=[0 0 0] means that the voxel (a,b,c) in input will be at
% point (a,b,c) in the output.
%shift=[2 -2 0] means that voxel (a,b,c) will be at (a+2, b-2, c) in
%output.
%
% Note - this used to add on volume to another, rather than place one image
% in the other. I have modified so it no longer adds. Hope this doesn't
% break anything.
[sizeYi, sizeXi, sizeZi]=size(input);
[sizeYo, sizeXo, sizeZo]=size(output);
%output(y1o:y2o, x1o:x2o, z1o:z2o)=output(y1o:y2o, x1o:x2o, z1o:z2o)+input(y1i:y2i, x1i:x2i, z1i:z2i);
y=shift(1);x=shift(2);z=shift(3);
%output volume limits
y1o=max(1, y+1);
y2o=min(sizeYo, y+sizeYi);
x1o=max(1, x+1);
x2o=min(sizeXo, x+sizeXi);
z1o=max(1, z+1);
z2o=min(sizeZo, z+sizeZi);
%input volume limits
y1i=max(1, -y+1);
y2i=min(sizeYi, sizeYo-y);
x1i=max(1, -x+1);
x2i=min(sizeXi, sizeXo-x);
z1i=max(1, -z+1);
z2i=min(sizeZi, sizeZo-z);
%output(y1o:y2o, x1o:x2o, z1o:z2o)=output(y1o:y2o, x1o:x2o,z1o:z2o)+input(y1i:y2i, x1i:x2i, z1i:z2i);
output(y1o:y2o, x1o:x2o, z1o:z2o)=input(y1i:y2i, x1i:x2i, z1i:z2i);