R13 imadd (under MATLAB6p5\toolbox\images\images)
function Z = imadd(X,Y,output_class)
%IMADD Add two images, or add constant to image.
% Z = IMADD(X,Y) adds each element in array X to the corresponding
% element in array Y and returns the sum in the corresponding element
% of the output array Z. X and Y are real, nonsparse, numeric arrays
% with the same size and class, or Y is a scalar double. Z has the
% same size and class as X.
%
% Z = IMADD(X,Y,OUTPUT_CLASS) specifies the desired output class of Z.
% OUTPUT_CLASS must be one of the following strings: 'uint8', 'uint16',
% 'uint32', 'int8', 'int16', and 'int32', 'single, 'double'.
%
% If Z is an integer array, then elements in the output that exceed the
% range of the integer type are truncated, and fractional values are
% rounded.
%
% If X and Y are double arrays, you can use the expression X+Y instead of
% this function.
%
% Example 1
% ---------
% Add two images together:
%
% I = imread('rice.tif');
% J = imread('cameraman.tif');
% K = imadd(I,J);
% imshow(K)
%
% Example 2
% ---------
% Add two images together and specify an output class:
%
% I = imread('rice.tif');
% J = imread('cameraman.tif');
% K = imadd(I,J,'uint16');
% imshow(K,[])
%
% Example 3
% ---------
% Add a constant to an image:
%
% I = imread('rice.tif');
% J = imadd(I,50);
% subplot(1,2,1), imshow(I)
% subplot(1,2,2), imshow(J)
%
% See also IMABSDIFF, IMCOMPLEMENT, IMDIVIDE, IMLINCOMB, IMMULTIPLY, IMSUBTRACT.
% Copyright 1993-2002 The MathWorks, Inc.
% $Revision: 1.9 $ $Date: 2002/03/15 15:27:41 $
checknargin(2, 3, nargin, mfilename);
if (nargin < 3)
output_class = class(X);
else
valid_strings = {'uint8' 'uint16' 'uint32' 'int8' 'int16' 'int32' ...
'single' 'double'};
output_class = checkstrs(output_class, valid_strings, mfilename, ...
'OUTPUT_CLASS', 3);
end
if (prod(size(Y)) == 1) & isa(Y, 'double')
Z = imlincomb(1.0, X, Y, output_class);
else
Z = imlincomb(1.0, X, 1.0, Y, output_class);
end