All we have to do is to apply a discrete algorithm on the histogram formed in the previous chapter. The length of the interval is CLIP, and we can find its position by shifting the interval along the complete histogram in discrete steps of one. In each step the error sum is increased by the outgoing histogram member and decreased by the incoming one. The pseudo code is given in algorithm 1.

Algorithm 1
The optimum clipping interval starts at H[best], and
ends at H[best+CLIP-1]. The algorithm runs in linear time
. The actual [a,b] interval is then:


or in linear scale:


Now clipping can be done at [A,B] and the final image can be
generated. Figure 6.2 shows a logarithmic histogram of the
images shown in color plates 1 and 2, and the optimum clipping
interval for contrast C=50.

Figure 6.2: Logarithmic histogram with optimum interval of C=50