Add two images or add constant to image
This example shows how to add two
uint8 arrays with truncation for values that exceed 255.
X = uint8([ 255 0 75; 44 225 100]); Y = uint8([ 50 50 50; 50 50 50 ]); Z = imadd(X,Y)
Z = 2x3 uint8 matrix 255 50 125 94 255 150
Read two grayscale
uint8 images into the workspace.
I = imread('rice.png'); J = imread('cameraman.tif');
Add the images. Specify the output as type
uint16 to avoid truncating the result.
K = imadd(I,J,'uint16');
Display the result.
Read an image into the workspace.
I = imread('rice.png');
Add a constant to the image.
J = imadd(I,50);
Display the original image and the result.
X— First array
First array, specified as a real, nonsparse, numeric or logical array of any dimension.
Y— Second array
Second array to be added to
X, specified as a real,
nonsparse, numeric or logical array.
Y either has the
same size and class as
a scalar of type
Sum, returned as a numeric array of the same size as
Z is the same class as
X is logical, in
Z is data type
X is an integer array, elements of the output that
exceed the range of the integer type are truncated, and fractional values