Image Processing — Gray Level Transformation: Part 5

Kavini Welarathne
3 min readJul 26, 2022

--

Goal

  • Apply Negative transformation for color images
  • Apply Power-law transformation/Gamma correction to improve the contrast of images 
  • Apply Log transformation to improve the dynamic range of images

Let’s begin with this definition.

What is Gray Level Transformation?

The gray level transformation can be used as an image enhancement technique. A gray level image consists of 256 levels of gray in a histogram. The Horizontal axis ranges from 0 to 255, and the vertical axis relies on the number of pixels in the image.

There are three types of transformation:

  1. Linear
  2. Logarithmic
  3. Power — law

1. Linear transformation

Okay. First, I will explain the linear transformation.

There are two types:

1.1 Identity transformation

Here each value of the input image is directly mapped to the output image values.

1.2 Negative transformation

This is the opposite of identity transformation. Each value of the input image is subtracted from the L-1 and mapped onto the output image.

Apply Negative transformation to color images

Let’s see the code now:

So what happens is, that the lighter pixels become dark and the darker picture becomes light. And it results in an image negative.

It is shown in the graph below.

Input image vs Output image

Now let’s try to understand…

2. Logarithmic transformations

Logarithmic transformation contains two types of transformation.

1.Log transformation

2. inverse log transformation.

2.1 Log transformation

This formula can be used to define log transformations.

s = c log(r + 1).

Here what happens is, that darker pixels are expanded relative to higher pixels. The higher pixel values are compressed in log transformation.

Let’s work with an example!

Apply Log transformation to improve the dynamic range of an image

Input image vs Output image

Here You can see, How darker pixels and higher pixels are located.

Ugh…give me a break…

Anyway. Let’s master the

3. Power—Law transformations

Power-Law transformations function can be defined as:
s=cr^γ

This symbol γ is called gamma, so this transformation is also known as gamma transformation.

The enhancement of the images depends on the variation of the γ value.

Different types of display devices use this type of transformation to enhance images.

Let’s see the code now:

Apply Power-law transformation to improve the contrast of a dark image

Input image vs Output image

Okay, That’s it for today. !

You should now have a good idea of how to work with Gray Level Transformation, as well as its practices.

Note: Here I’ve attached an image file for your convenience.

I hope you found this article useful! You can follow me on Medium. Feel free to leave any questions in the comments below. I’ll be glad to help out!

See you guys in the next article! ❤️ ✌

--

--

Kavini Welarathne
Kavini Welarathne

Written by Kavini Welarathne

Software Engineer | Researcher |

Responses (1)