Pixel Overflow


When performing pixel arithmetic, the result of the operation may not fit within the pixel data type. This experiment illustrates this problem by adding a constant to all image pixels.

------
Original image: unsigned byte_______Result of adding 80 to its pixels

The problem with the above image is that the pixel data type is unsigned byte. With this data type we can only represent values from 0 to 255. Adding 80 to 255 gives (255+80) - 256 = 79 (wraparound), which is a dark pixel value.

To solve this wraparound effect, we can convert the pixel data type to unsigned short (16 bits) and then perform the addition.


Result with data type short



DIP Feedback Form

Copyright © 1995 KRI, ISTEC, Ramiro Jordán, Roberto Lotufo. All Rights Reserved.