Roundify
![x "mkdir -p img" 256,1,1,1,'256*x/w' repeat 4 +normalize[0] 0,4 roundify. {$>/2} done rm[0] append c display_graph. 1200,900,1,4 r2dx. 50%,5](img/x_mkdir_p_img_256_1_1_1_256_x_w_repeat_4_normalize_0_0_4_roundify_2_done_rm_0_append_c_display_graph_1200_900_1_4_r2dx_50_5.png)
Transitions fast or slow, as you like them.
Unlike round, roundify also provides "soft" transitions (green curve). Gamma settings taken from the open interval (0, ... 1) replace the abrupt unit transitions with gamma curves, each centered on the transition value, that "eases in" from n - 0.5 and "eases out" to _n + 0.5, with an average slope inversely proportional to the gamma value: a large slope with small gamma values. Visually this "softens" the transition boundary. The average curve slope lessens with increased gamma, further softening the transitions, until gamma equals 1.0 and the gamma curves become linear ramps (blue curve). Gamma may exceed 1.0, shifting transition points to the integral values themselves and causing shifted, semiflat regions (bluegreen curve).
Examples:
Mach Banding, where luminance values cluster around just a very few values, often drive photographers and artists nuts – unless, of course, that is the effect wanted. Mach banding, named after Austrian physicist Ernst Mach, typically occurs in a workflow where unsigned integer-based calculations are taking place, and, in their course, luminosity ranges are compressed to just very narrow boundaries. Being unsigned integers, the luminosity values necessarily crowd into just a very few values.The results are very well known. What, in the original is a uniform progression of values, becomes a series of abrupt transitions. Should that be the desired effect, great! But if it is not desired... no joy. To compensate, one may apply a dither pattern around the transition edges, but that is often destructive to fine detail. Sometimes, the effect is unavoidable. The unsigned integer compression and expansion is happening in hardware, or in compensation for noisy transmission. Dithering is then a necessary crutch.
But if Mach banding is a desired effect, then roundify presents the means to cluster luminosity into specific value bins with both hard or soft transitions. If desired, roundify may cluster luminosity values to just a very few values, the classic posterization effect. But roundify also allows values near transition edges to drift a bit toward intermediary values, neither in one bin nor the other. These near-transition values are not represented well by either neighboring bin, so roundify lets them assume luminosities closer to their original values, but only to an extent. That extent is controlled by the gamma parameter. When it is zero, no drift is allowed. Transition values fall into one bin or the other. When one, it is as if roundify has not even operated: uniform progressions of values remain so. Usually, one chooses an intermediary gamma value to force "some" binning with "some" relaxation near transitions:
Original | Gamma = 0 | Gamma = 0.3333 | Gamma = 0.6667 | Gamma = 1.0000 |
![]() | ![]() | ![]() | ![]() | ![]() |
To harness roundify for distinct artistic pursuits, first normalize the image to a narrow range. To "posterize" a continuous-tone image into four luminosity zones, first normalize to a [0...4] range:

A car, unroundified
![sp car,150 repeat 4 +n[0] 0,4 -roundify. {$>/3} n. 0,255 done rm[0]](img/sp_car_150_repeat_4_n_0_0_4_roundify_3_n_0_255_done_rm_0_.png)
A car: roundify gammas of 0, 1/3, 2/3 and 1.0
gmic \
-sample car,200 \
-repeat 4 \
+normalize[0] 0,4 \
-roundify. '{$>/3}' \
-normalize. 0,255 \
-done \
-sample car,200 \
-repeat 4 \
+normalize[0] 0,4 \
-roundify. '{$>/3}' \
-normalize. 0,255 \
-done \