Home > SuperSegger > Internal > imshift.m

imshift

PURPOSE ^

imshift : shifts an array by 'offest' and pads the offset with zeros.

SYNOPSIS ^

function maskShifted = imshift(mask, offset)

DESCRIPTION ^

 imshift : shifts an array by 'offest' and pads the offset with zeros.
 Used to shift masks upwards, downwards, right and left.

 INPUT :
    mask : input binary mask
    offset : [x,y] offset. Negative signifies shift upwards/ left.

 OUTPUT :
   maskShifted : shifted binary mask

 Copyright (C) 2016 Wiggins Lab
 Written by Stella Stylianidou
 University of Washington, 2016
 This file is part of SuperSegger.

 SuperSegger is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 SuperSegger is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function maskShifted = imshift(mask, offset)
0002 % imshift : shifts an array by 'offest' and pads the offset with zeros.
0003 % Used to shift masks upwards, downwards, right and left.
0004 %
0005 % INPUT :
0006 %    mask : input binary mask
0007 %    offset : [x,y] offset. Negative signifies shift upwards/ left.
0008 %
0009 % OUTPUT :
0010 %   maskShifted : shifted binary mask
0011 %
0012 % Copyright (C) 2016 Wiggins Lab
0013 % Written by Stella Stylianidou
0014 % University of Washington, 2016
0015 % This file is part of SuperSegger.
0016 %
0017 % SuperSegger is free software: you can redistribute it and/or modify
0018 % it under the terms of the GNU General Public License as published by
0019 % the Free Software Foundation, either version 3 of the License, or
0020 % (at your option) any later version.
0021 %
0022 % SuperSegger is distributed in the hope that it will be useful,
0023 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0024 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0025 % GNU General Public License for more details.
0026 %
0027 % You should have received a copy of the GNU General Public License
0028 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0029 
0030 
0031 maskShifted = mask;
0032 maskSS = size(mask);
0033 
0034 % y direction
0035 if offset(2) < 0 % upwards
0036     shiftInY = abs(offset(2));
0037     zeroPad = zeros(min(maskSS(1),shiftInY),maskSS(2));
0038     maskShifted = [maskShifted(shiftInY+1:end,:);zeroPad];
0039 
0040 else % downwards
0041     shiftInY = abs(offset(2));
0042     zeroPad = zeros(min(maskSS(1),shiftInY),maskSS(2));
0043     maskShifted = [zeroPad;maskShifted(1:end-shiftInY,:)];
0044 
0045 end
0046 
0047 if offset(1) < 0 % left
0048     shiftInX = abs(offset(1));
0049     zeroPad = zeros(maskSS(1),min(maskSS(2),shiftInX));
0050     maskShifted = [maskShifted(:,shiftInX+1:end),zeroPad];
0051 
0052 else % right
0053     shiftInX = abs(offset(1));
0054     zeroPad = zeros(maskSS(1),min(maskSS(2),shiftInX));
0055     maskShifted = [zeroPad,maskShifted(:,1:end-shiftInX)];
0056 
0057 end
0058 
0059 
0060 end

Generated on Thu 19-Jan-2017 13:55:21 by m2html © 2005