Main Content

Nest Calls to Image Arithmetic Functions

You can use the image arithmetic functions in combination to perform a series of operations. For example, to calculate the average of two images,


You could enter

I = imread('rice.png');
I2 = imread('cameraman.tif');
K = imdivide(imadd(I,I2),2); % not recommended 

When used with uint8 or uint16 data, each arithmetic function rounds and clips its result before passing it on to the next operation. This can significantly reduce the precision of the calculation.

A better way to perform this calculation is to use the imlincomb function. imlincomb performs all the arithmetic operations in the linear combination in double precision and only rounds and clips the final result.

K = imlincomb(.5,I,.5,I2); % recommended 

See Also

Related Topics