% thresh (Thresholding function) by Dan Piehl (2006) % % This will set all values to zero which are within a threshold value. % It can accept one, two, or three dimensional inputs, and requires the % specification of a threshold parameter. % Thresholds can be "soft" if an exponent is supplied (e.g. 1). % The third dimension (for color) may be added if desired. function b = thresh(a,threshold,softexponent) % 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 < 2) error('MATLAB:wavelet:NoInputs',['Not enough input arguments specified.']) end if (numDimsA<1 || numDimsA>3) % Only 1/2/3 dimensional arrays are allowed error('MATLAB:wavelet:NoInputs',['Invalid array dimensions.']) end if not ( S1>=1 && S2>=1 && S3>=1 ) error('MATLAB:wavelet:NoInputs',['Invalid array dimensions.']) end % Set everything below threshold to zero (or softened value) b=a; % Reset the output array if (threshold>0) % If a threshold is provided if (S3==1) n=abs(b)/threshold; else n=sqrt(sum(b.^2,3))/threshold; % Compute euclidean end n=min(cat(3,n,ones(S1,S2)),[],3); % Keep bounded at one if (nargin==3) % For soft threshold... n=n.^softexponent; % Apply exponent else % Otherwise... n=floor(n); % Flip values less than one to zero end for iteration=1:S3 % Apply to each color plane b(:,:,iteration)=b(:,:,iteration).*n; end end