This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Add two images or add constant to image


Z = imadd(X,Y)


Z = imadd(X,Y) adds each element in array X with 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, unless X is logical, in which case Z is double.

If X and Y are integer arrays, elements in the output that exceed the range of the integer type are truncated, and fractional values are rounded.


collapse all

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.



Introduced before R2006a

Was this topic helpful?