% lowpass (Low pass filter function) by Dan Piehl (2006) % % This will determine perform a basic low pass filter operation % on one or two dimensional data. The filter is a simple % three-point filter for 1-D arrays, or a 9-point for 2-D and 3-D arrays. % The third dimension is always interpreted as a color subscript. % % Note: This function reflects boundary values, so that filtering assumes % values outside the array are equal to values on the array boundary function b = lowpass(a) % Examine parameters and return error messages, if needed numDimsA = ndims(a); % Get the number of input dimensions S1=size(a,1); % Get the number of rows S2=size(a,2); % Get the number of columns S3=size(a,3); % Get the number of color planes if (nargin < 1) error('MATLAB:wavelet:NoInputs',['No input arguments specified.']) end if (numDimsA<1 || numDimsA>3) % Only 1-3 dimensional arrays are allowed error('MATLAB:wavelet:NoInputs',['Invalid array dimensions.']) end if not ( (S1==1 && S2>1) || (S1>1 && S2==1) || (S1>1 && S2>1) ) error('MATLAB:wavelet:NoInputs',['Invalid array dimensions.']) end % Perform lowpass filtering b=a; for iteration=1:S3 if (S1==1) % For a single row... t=conv([1 2 1]/4,cat(2,a(:,1,iteration),a(:,:,iteration),a(:,S2,iteration))); b(:,:,iteration)=t(1,3:S2+2); elseif (S2==1) % For a single column... t=conv([1 2 1]/4,cat(1,a(1,:,iteration),a(:,:,iteration),a(S1,:,iteration))); b(:,:,iteration)=t(3:S1+2,1); else % For 2-D or 3-D array... t=cat(1,a(1,:,iteration),a(:,:,iteration),a(S1,:,iteration)); t=convn([1 2 1; 2 4 2; 1 2 1]/16,cat(2,t(:,1),t,t(:,S2))); b(:,:,iteration)=t(3:S1+2,3:S2+2); end end