% imclip (Image value clipping function) by Dan Piehl (2006) % % This will set all values to zero which are negative. % It will also set values to one which exceed one. function b = imclip(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 colors if not (nargin == 1) error('MATLAB:wavelet:NoInputs',['Not enough 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 && S3>=1 ) error('MATLAB:wavelet:NoInputs',['Invalid array dimensions.']) end % Check values b=real(a); % Ignore imaginary components b=max(cat(4,b,zeros(S1,S2,S3)),[],4); % Clip at lower bound (zero) b=min(cat(4,b,ones(S1,S2,S3)),[],4); % Clip at upper bound (one)