% FUNCTION Y = DILATION2(X, N_TIMES) function y = dilation2(x, n_times) if n_times < 0 error( 'dilation needs n_times >= 0' ); end siz = size( x ); if sum( siz>1 ) > 1 disp( 'dilation: WARNING! Input has more than one dimension.' ); end if n_times < 1 y = x; return; end x = x(:); % Mirror-replicate beginning and end of data vector n_left = min( length( x ), n_times ); fill_left = x( n_left:-1:1 ); fill_left = [ repmat( fill_left( 1 ), n_times-n_left, 1 ); fill_left ]; n_right = min( length( x ), n_times ); fill_right = x( end:-1:end-n_right+1 ); fill_right = [ fill_right; repmat( fill_right( end ), n_times-n_right, 1 ) ]; aux = [fill_left; x(:); fill_right]; aux2 = aux; for a = ( 1+n_times ):( numel( aux )-n_times ) aux2( a ) = max( aux( a-n_times:a+n_times ) ); end y = aux2((1+n_times):(end-n_times)); y = reshape( y, siz );