Function File: out = imsubtract (a, b)
Function File: out = imsubtract (a, b, class)

Subtract image or constant to an image.

If a and b are two images of same size and class, b is subtracted to a. Alternatively, if b is a floating-point scalar, its value is subtracted to the image a.

The class of out will be the same as a unless a is logical in which case out will be double. Alternatively, it can be specified with class.

Note 1: you can force output class to be logical by specifying class. This is incompatible with MATLAB which will not honour request to return a logical matrix.

Note 2: the values are truncated to the mininum value of the output class.

Note 3: values are truncated before the operation so if input images are unsigned integers and the request output class is a signed integer, it may lead to unexpected results:

imsubtract (uint8 ([23 190]), uint8 ([24 200]), "int8")
     ⇒ -1  0

Because both 190 and 200 were truncated to 127 before subtraction, their difference is zero.

See also: imabsdiff, imadd, imcomplement, imdivide, imlincomb, immultiply.

Package: image