Posterize issues and strange math in Compositor

Hello. I wanted to get some posterization effect on a grayscale image in the compositor.

I searched here for some way to do it as there’s no pre-built posterize effect. I found this old thread but it doesn’t seem to work any more (output totally black). More search revealed that apparently the round math node doesn’t use the second value (maybe it used to) and always rounds integer. According to the documentation, the correct way to posterize a channel is thus to first multiply the channel by N (amount of colors you want in the processed image), substract 0.5001 (for rounding) and then divide by N-1 so i built a group node to handle this.

I was extremely surprised by the result thought, as a lot of areas were pitch black even thought i had almost no pure black or very low values. Even areas with a value around 0.27 were black after posterizing for 10 shades of gray. I decide to test on something simple and thus put a simple Suzanne with a single light, basic light gray diffuse and rendered. Even before i had finished re-building my posterize setup i noticed something strange. After the first multiply i was able to see a lot of shades of gray on the composited image while i was expecting to see mostly white (as anything with a value of 0.1 or more should turn pure white after being multiplied by 10).

You can see the result of the simple node. Left Suzanne is basic render, right is node effect. I tested the gray background, it has a value of 0.25 before the node effect and 0.7411 after being multiplied by 10! Not exactly the maths i’m used to.


So i have 2 questions.

  • What’s going on with the math node in the compositor?
  • How am i supposed to do a posterize effect if the math node gives me such strange results?

I read this last night and, not having a reasonable answer, decided on a controlled experiment. I setup a world with a simple black/white “studio” EXR environment image I use for material development and forced anything in the background (non-Suzanne in this case) to a .25 value:


(Any environment setup will do, the importance in this test is the flat uninfluenced background.) I then recreated your node setup with a 10 multiplier and a split viewer, rendered layer on the left, composited on the right. Suzanne is diffuse with gray created from a Combine HSV node, value set to 0.5.


I seem to be getting the results you were expecting. Is your background a plane? Is it possible the color picker you used to determine a value of 0.7411 is sampling a non-white pixel?

So you need to (separate to RGB then) Subtract a Modulo of source image from the source image.
It sucks that Round doesn’t just work anymore. Oh well.