Use equalization to precompute a mapped level s(k) for each level r(k).
Obtain the transformation function G from the specified histogram using
equalization.
Precompute z(k) for each value s(k).
For each pixel in the original image, if the value of that
pizel is r(k), map this value to the corresponding level s(k); then
map level s(k) into the final level z(k). Use precomputed values
for these mappings.