-2

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

Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
  • @camelccc: I will get negative values that way.... and having in mind the lowest value is zero, I'm gonna make a wild guess and say that's a terrible suggestion. – Flame_Phoenix Mar 25 '13 at 12:06
  • 2
    and if your range of values is 0 - 255 just how can you get a negative value subtracting a no smaller than 255 from 255 ? – camelccc Mar 25 '13 at 12:09
  • @camelccc: Ohhh, now I get it. I was reading the answer backwards. I have this terrible habit sry. If you transform that comment into an answer I can "select" it and give it karma++ :D Thx! Dumb me. – Flame_Phoenix Mar 25 '13 at 12:13

1 Answers1

2

If range of values is 0 - 255

Inverse is 255 - value

camelccc
  • 2,847
  • 8
  • 26
  • 52