Pseudocode
PROCEDURE negative(image)
FOR x = 0 .. width DO
FOR y = 0 .. height DO
c <- pixel(x, y)
FOR i = 0 .. 3 DO
c`_i <- 255 - c_i
END FOR
pixel(x, y) <- c'
END FOR
END FOR
END PROCEDURE
Where
-
The valid range of a channel is 0 .. 255
Description
Loop through all pixels in the image, for each channel in the pixel calculate the new value by subtracting its maximum possible value (255 in the example code) from its current value. Set the pixel to be this newly calculated value.
Acknowledgements
Adapted from Pseudocode produced for COMP120 by Dr. Micheal Scott.