0001 function Bout = vb_dilation_3d_int(B, R)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 B = int8(B);
0024
0025 [N1,N2,N3] = size(B);
0026
0027 Bout = B;
0028
0029
0030
0031 Bo = zeros(N1,N2,N3,'int8');
0032 iz = find( B == 0 );
0033 Bo(iz) = 1;
0034
0035
0036
0037 j1d = 1:(N1-1);
0038 j1u = 2:N1;
0039
0040 j2d = 1:(N2-1);
0041 j2u = 2:N2;
0042
0043
0044 Rmax = ceil(R);
0045 x = -Rmax:Rmax;
0046
0047 [x1, x2, x3 ] = ndgrid(x);
0048
0049 jx = find( (x1.^2 + x2.^2 +x3.^2 ) <= R^2 );
0050
0051 x1 = x1(jx);
0052 x2 = x2(jx);
0053 x3 = x3(jx);
0054
0055 NN = length(jx);
0056 N1N2 = N1*N2;
0057
0058 Bx = zeros(N1,N2, 'int8');
0059
0060 for zz = 1:N3
0061
0062 Bx = zeros(N1,N2, 'int8');
0063
0064
0065
0066 Bx(j1d, : ) = Bx(j1d, : ) + Bo(j1u, : , zz );
0067 Bx(j1u, : ) = Bx(j1u, : ) + Bo(j1d, : , zz );
0068 Bx( : ,j2d) = Bx( : ,j2d) + Bo( : ,j2u, zz );
0069 Bx( : ,j2u) = Bx( : ,j2u) + Bo( : ,j2d, zz );
0070
0071 if zz > 1,
0072 Bx = Bx + Bo(:,:,zz-1);
0073 end
0074 if zz < N3,
0075 Bx = Bx + Bo(:,:,zz+1);
0076 end
0077
0078
0079 Bx = Bx.*B(:,:,zz);
0080
0081
0082 iz = find( Bx > 0 );
0083 Nz = length(iz);
0084
0085
0086
0087 j3 = zz;
0088 j2 = floor((iz-1)/N1)+1;
0089 j1 = rem((iz-1),N1)+1;
0090
0091
0092 k1 = zeros(Nz,1);
0093 k2 = zeros(Nz,1);
0094
0095 for n=1:NN,
0096
0097 k1 = j1 + x1(n);
0098 k2 = j2 + x2(n);
0099 k3 = j3 + x3(n);
0100
0101
0102 k1 = max(k1,1);
0103 k2 = max(k2,1);
0104 k3 = max(k3,1);
0105
0106 k1 = min(k1,N1);
0107 k2 = min(k2,N2);
0108 k3 = min(k3,N3);
0109
0110
0111
0112 inx = k1+ N1*(k2 - 1)+ N1N2*(k3 - 1);
0113
0114 Bout(inx) = 1;
0115 end;
0116 end