1. A method for processing an input image comprising intensity values, the method comprising: calculating an intensity value distribution for the input image; forming a first piecewise linear transform, the first piecewise linear transform configured to transform the intensity distribution of the input image, the first piecewise linear transform comprising a sequence of first segments, each segment of the sequence of first segments having a gain, the sequence of first segments being connected at a first plurality of breakpoints, the difference between the respective gains of any pair of segments, of the sequence of first segments, connected at a breakpoint of the first plurality of breakpoints being less than a first gain change limit, forming a second piecewise linear transform, the second piecewise linear transform comprising a sequence of second segments corresponding to a pair of first segments connected at one of the first plurality of breakpoints, each segment of the sequence of second segments having a gain, the sequence of second segments being connected at a second plurality of breakpoints, the difference between the respective gains of any pair of segments, of the sequence of second segments, connected at a breakpoint of the second plurality of breakpoints being less than a second gain change limit, the second gain change limit being less than the first gain change limit; and mapping the intensity values of the input image to modified intensity values using the second linear piecewise transform.