Search code examples
inverse

Get NetPBM negative image (Math formula)


I have a file of integer values that range from 0 to 255. A value of zero means black pixel while a value of 255 means a white pixel. Values in between are "gray-like colors". I am searching for a way to invert that file so that 255 gets transformed into 0 and 0 gets transformed in 255 (per example), thus allowing me to successfully obtain the negative of the image.

Is there a way to achieve this? I am sure the answer is a simply mathematical formula using modulo but I can't get to it.

For additional please refer to: NetPBM


Solution

  • If range of values is 0 - 255

    Inverse is 255 - value