Image Arithmetic Clipping Rules

The results of integer arithmetic can easily overflow the data type allotted for storage. For example, the maximum value you can store in uint8 data is 255. Arithmetic operations can also result in fractional values, which cannot be represented using integer arrays.

MATLAB® arithmetic operators and the Image Processing Toolbox™ arithmetic functions use these rules for integer arithmetic:

  • Values that exceed the range of the integer type are clipped, or truncated, to that range.

  • Fractional values are rounded.

For example, if the data type is uint8, results greater than 255 (including Inf) are set to 255. The table lists some additional examples.

Result

Class

Clipped Value

300

uint8

255

-45

uint8

0

10.5

uint8

11

Related Topics