matRad add margin function call mVOIEnlarged = matRad_addMargin(mVOI,cst,vResolution,vMargin,bDiaElem) input mVOI: image stack in dimensions of X x Y x Z holding ones for object and zeros otherwise cst: matRad cst struct vResolution ct resolution vMargin: margin in mm bDiaElem if true 26-connectivity is used otherwise 6-connectivity output mVOIEnlarged: enlarged VOI References - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright 2015 the matRad development team. This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function mVOIEnlarged = matRad_addMargin(mVOI,cst,vResolution,vMargin,bDiaElem) 0002 % matRad add margin function 0003 % 0004 % call 0005 % mVOIEnlarged = matRad_addMargin(mVOI,cst,vResolution,vMargin,bDiaElem) 0006 % 0007 % input 0008 % mVOI: image stack in dimensions of X x Y x Z holding ones for 0009 % object and zeros otherwise 0010 % cst: matRad cst struct 0011 % vResolution ct resolution 0012 % vMargin: margin in mm 0013 % bDiaElem if true 26-connectivity is used otherwise 6-connectivity 0014 % 0015 % output 0016 % mVOIEnlarged: enlarged VOI 0017 % 0018 % References 0019 % - 0020 % 0021 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0022 % 0023 % Copyright 2015 the matRad development team. 0024 % 0025 % This file is part of the matRad project. It is subject to the license 0026 % terms in the LICENSE file found in the top-level directory of this 0027 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 0028 % of the matRad project, including this file, may be copied, modified, 0029 % propagated, or distributed except according to the terms contained in the 0030 % LICENSE file. 0031 % 0032 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0033 0034 if nargin == 4 0035 bDiaElem = false; 0036 elseif nargin < 4 0037 error('not enough input parameters specified for matRad_addMargin'); 0038 end 0039 0040 % generate voi cube for patient surface/patient skin 0041 idx = [cst{:,4}]; 0042 voiSurfaceIdx = unique(vertcat(idx{:})); 0043 0044 % get number of voxels which should be added in each dimension 0045 voxelMargins = round([vMargin.x vMargin.y vMargin.z]./[vResolution.x vResolution.y vResolution.z]); 0046 mVOIEnlarged = mVOI; 0047 newIdx = []; 0048 0049 [yUpperLim,xUpperLim,zUpperLim] = size(mVOI); 0050 0051 for cnt = 1:max(voxelMargins) 0052 0053 % for multiple loops consider just added margin 0054 newIdx = setdiff(find(mVOIEnlarged),newIdx); 0055 [yCoord, xCoord, zCoord] = ind2sub(size(mVOIEnlarged),newIdx); 0056 0057 % find indices on border and take out 0058 borderIx = xCoord==1 | xCoord==xUpperLim | ... 0059 yCoord==1 | yCoord==yUpperLim | ... 0060 zCoord==1 | zCoord==zUpperLim; 0061 0062 xCoord(borderIx) = []; 0063 yCoord(borderIx) = []; 0064 zCoord(borderIx) = []; 0065 0066 dx = voxelMargins(1)>=cnt; 0067 dy = voxelMargins(2)>=cnt; 0068 dz = voxelMargins(3)>=cnt; 0069 0070 for i = -1:1 0071 for j = -1:1 0072 for k = -1:1 0073 0074 if (abs(i)+abs(j)+abs(k) == 0) || (~bDiaElem && abs(i)+abs(j)+abs(k) > 1) % skip if diagonal elements not wanted or zero offset 0075 continue; 0076 end 0077 0078 newIx = (yCoord+i*dy) + (xCoord+j*dx-1)*size(mVOIEnlarged,1) + ... 0079 (zCoord+k*dz-1)*size(mVOIEnlarged,1)*size(mVOIEnlarged,2); 0080 0081 % check if new indices are part of voiSurfaceIdx 0082 bWithinPatient = ismember(newIx,voiSurfaceIdx); 0083 0084 mVOIEnlarged(newIx(bWithinPatient)) = 1; 0085 0086 end 0087 end 0088 end 0089 0090 0091 end 0092