Published May 19, 2022 - By Marco Garosi
Images can be processed in various ways. Sometimes you just want to enhance them; some other times, you want to extract features. In order to achieve your goal, you should know and understand what kind of elaborations can be made, how they work and how they affect the image.
Now, there are three different kinds of image processing techniques:
- pixel-based, which mainly work on the contrast;
There are a bunch of different pixel-based filters you may want to apply to an image. Here are the most important ones.
It does literally nothing: for each pixel it gives back its exact value.
It inverts the image. Every pixel gets a new value — call it — which is , where is the maximum level of grey (usually ).
It is defined as follows:
It “cuts” the left-most and right-most parts of the histogram by moving all the values outside of the domain into the domain itself (by replacing them with when they’re lower — on the left-most part of the histogram; and with when they’re higher — on the right-most part of the histogram).
It stretches the image from a range to a new range . The function that does that is:
Of course, the stretching is “linear”, meaning that the produced histogram looks like a straight line for the extended part.
That is defined as: . is called the normalization constant and ensures us to map the output on the range , without ever exceeding it.
Constant can be computed as
The output value is computed as follows: . If:
- , the transform is equivalent to the logarithmic transform (which expands lower values and compresses higher ones);
- , the transform does the opposite (it expands higher values and compresses lower ones).
- , the transform does nothing -- it is equivalent to the identity.
Binarizations works on the assumption that there are two regision to split up. It produces a black and wite image: pixels are either white (255) or black (0), with no intermediary values. One of the most used methods is Otsu’s Method.
Otsu’s thresholding tries to minimize the intra-class variance: it basically tries to binarize at each value from 0 up to 255 and keeps the one that better minimizes intra-class variance.
In order for Otsu’s thresholding to work the best, the histogram should have two bell-shaped groups of values differently skewed — it is thus possible to find a value between them that best divides them.
Otsu’s technique actually minimizes the following formula:
Where and .
It loops over all the possible values for ( , where is usually ) and returns .
Histogram equalization makes the contribution of each grey level similar, thus making the histogram look as uniform as possible (the histogram is said to have the highest entropy).
It is an algorithm, actually: it cannot be computed pixel-independentely since it “spreads” the values on the whole histogram — and does so by taking into account how many pixels there are for each different grey value.
- Compute the cumulative sums , with .
- Multiply each of the previously computed cumulative sums by the highest available grey level ( ).
- Normalize the values by dividing by .
- Apply the mapping produced.
Let’s take a simple histogram to make an example. The highest grey level (GL) is , so there are different grey levels.
- Step 1: cumulative sum
- Step 2: multiply by
- Step 3: normalization
- Step 4: apply the mapping
For each grey level in the previous table a rounded value was produced: that’s the value to substitute for the corresponding grey level. The table is indeed a Look-Up Table (LUT) that maps grey levels to new values. Of course, the LUT mapping has to be applied to every pixel in the image.