# IV – Logarithmic Transformation

A logarithmic transformation of an image is actually a simple one. We simply take the logarithm of each pixel value, and we’re done. Well, if that were the only interesting piece of information with respect to this topic, we’d be done now. There is an interesting operation we can carry out using some simple mathematics and a logarithmic transform: segmentation. This basically allows you to take an input image, with, for example, $x$ different possible pixel values, and produce an output image with $y$ possible pixel values. Although segmentation is a topic all on its own, this special case deserves a section for itself, if for no other reason than its simplicity.

In the case of the following images, I simply take an input image, calculate the base-2 logarithm of each pixel value, round it to the nearest integer (note the addition of a scalar $1$ to prevent a $log(0)$ calculation, which is NaN so far as MATLAB is concerned), and then normalize the image. While you don’t need to normalize the image (after all, the MATLAB $imagesc$ command does this for you easily enough), I figured it would be a good idea anyways.

The end result is shown below, along with the (simple) code used to generate it.