Posterization

Article Info

Pseudocode

PROCEDURE posterize(t_min, t_max, replacement)
    FOR x = 0 .. width DO
        FOR y = 0 .. height DO
            c <- pixel(x, y)

            IF t_min <= c_0 <= t_max THEN
                pixel(x, y) <- replacement
            END IF

        END FOR
    END FOR
END PROCEDURE

Where:

  • The minimum (t_min) and maximum (t_max) threshold values are in the correct range for the pixel (eg, 0..255)

  • The channel to be checked is denoted by c_0

Description

Loop through all pixels in the image, if the value of the pixel in a channel is within some treshold (t) in the above code, then replace it with the target colour.

Note this describes converting one colour. Many passes of this algorithm might be required (alternatively, this code could be modified to do multiple replacements in a single pass).

The algorithm also assumes that only one channel should be considered, you could modify this code to include checking thresholds for multiple channels (eg, t_min and t_max are vectors which are compared with c element-wise).

Acknowledgements

Adapted from Pseudocode produced for COMP120 by Dr. Micheal Scott.

Graduation Cap Book Open book GitHub Info chevron-right Sticky Note chevron-left Puzzle Piece Square Lightbulb Video Exclamation Triangle Globe