# Piece-wise Linear Transformation

Point transformation function for image enhancement discusses in **this post** are primitive in nature. Since manipulation of contrast is a difficult and subjective process, piece-wise linear function are used to manipulate the contrast of images. The main advantage of piece-wise function is that they can use simple functions to represent complex function for intensity transformation. The disadvantage is that they require many input parameters from the user.

**Contrast Stretching**

Contrast stretching is a linear mapping function used to manipulate the contrast of an image. In other words, it maps the values of the input image to the values of the output image. To make the process efficient we construct a Look Up Table (LUT). The contrast stretching process takes input value, refers to the LUT, and produce the output value. In the above transformation, the slope of three line segment \( (r_1, s_1)\) to \( (r_2, s_2)\), \( (r_2, s_2)\) to \( (r_3, s_3)\) and \( (r_3, s_3)\) to \( (r_4, s_4)\) are \(\frac{s_2-s_1}{r_2,r_1}\), \(\frac{s_3-s_2}{r_3,r_2}\) and \(\frac{s_4 – s_3}{r_4 – r_3}\). Lets denote these slope with \(l\), \(m\), and \(n\). Then above transformtion can be written as follows

$$s = \begin{cases} l \times (r – r_1) + s_1, & \text{if \(r < r_{2}\)}\\ m \times (r – r_{2}) + s_2, & \text{if \( r_{2} \le r \le r_{3} \) } \\ n \times (r – r_{3}) + s3, & \text{if \( r > r_{3} \) } \end{cases}$$

In the above transformation the intensity value between \(0\) to \(r_2\) and \(r_3\) to \(255\) are compressed while the range \(r_2\) to \(r_3\) are expanded.** When the slope is less than \(1\), dynamic range is reduced. The reduction in dynamic ranges result in a condition where the dark regions become darker. When the slope is greater than \(1\), brightness of the bright reason is further increased. Thus by controlling the parameters of the function, the contrast of an image can be controlled. **

Many variants of contrast stretching are available. Some of these variants such as **range normalization**, **clipping**, **binarization** and **posterizing** are discussed in below section.

**Range Normalization**

Range normalization is a special form of contrast stretching, which is used to enhance image quality by altering the range of grey levels present. Let us assume that the grey levels of an image range from \(a\) to \(b\). If the contrast range is required to be changed from \(c\) to \(d\), then the change can be accomplished by the following steps:

- Subtract \(a\) from each grey level so that the range now becomes \(0 – (b – a) \).
- Multiply the result by \(\frac{(d – c)}{(b – a)} \). Now the range becomes \(0 – (d-c) \).
- Add \(c\) to the result. This results in the range \( c -d\).

Above transformation can be described as: $$g(x,y) = \left[ \frac{(d-c)}{(b-a)} \right] \times \left[ f(x,y) – a\right] + c$$

**Clipping**

Low contrast images can be enhanced by cutting of very light and very dark areas. Clipping is a special type of contrast stretching where the image is supposed to be in the range \(\left[0 \dots L\right]\). The gray level function can be written as:

$$f(n) =

\begin{cases}

0, & \text{if \(0 \le f(x,y) < t_0\)} \\

\frac{255}{t_1 – t_0}, & \text{if \(t_0 \le f(x,y) < t_1\)} \\ L, & \text{if \( f(x,y) \ge t_1\)}

\end{cases}$$

Here the thresholds \(t_0\) and \(t_1\) can be determined from the histogram of the given image.

**Thresholding**

Thresholding is a special type of clipping process where two thresholds are the same. In thresholding, the transformation takes every pixel of the image and compares it with the threshold operation to get the corresponding pixel in the resultant image. The transformation can be written as follows:

$$g(x,y) =

\begin{cases}

0, & \text{if \( f(x,y) \le T \)} \\

1, & \text{if otherwise}

\end{cases}$$

Here, \(T\) is the user given threshold value. If \(T\) is too high resultant image is blank image. An optimal value of the threshold ensures good quality of the resultant image. Sometimes multiple thresholding is used to get the desired result.

**Binarization**

Binarization method is a special variants of thresholding were two thresholds are used. If the pixel value falls within these thresholds the value is set to maximum level, say \(255\) in a gray scale image. All the pixels outside the window is set to zero. This operation is called a **Windowing Operation** or **Binarization**.

**Posterizing or Multiple Thresholding**

This method is an extension of thresholding. In thresholding, only one threshold is used. However, in this method, multiple thresholds are used to map an image to its resultant image.

$$g =

\begin{cases}

g_1, & \text{if \(0 \le f_i \le t_1\)} \\

g_2, & \text{if \(t_1 \le f_i < t_2\)} \\ \;\vdots\; , & \text{ \(\qquad \vdots \)} \\ g_n, & \text{if \(t_{n-1} \le f_i \le 255\)}

\end{cases}$$

**Intensity Slicing**

Sometimes, it is necessary to highlight a specific range of intensity levels in an image. This is called the **Region of Interest (ROI)**. It is often required to enhance only the ROI and suppress the other features present in the image.

For example, if the ROI appears bright in a dark background, the brightness of the ROI can be further increased and the darkness of the background can be further decreased, thus increasing the contrast.

**Bit plane Slicing**

It is possible to transform a grey-level image into a sequence of binary image by taking advantage of its bit pattern storage. For example, a grey level image is stored as an \(8-bit\) image. Therefore, the image can be transformed into an eight-level image where the zero planes consists of the last bit of each grey level, the first plane consists of the first bit and so on. Similarly, the \(7^{th}\) plane consists of the most significant bit of each grey level.

This article is contributed by Ram Kripal. If you like eLgo Academy and would like to contribute, you can mail your article to admin@elgoacademy.org. See your article appearing on the eLgo Academy page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.