Friday, December 5, 2014

Enhancement: Brightness/Contrast and Transfer Function



The brightness and contrast of an image can be enhanced by modifying the transfer function or playing with the pixel distribution of the histogram. Here is the first part with the transfer function...


1. Playing with the transfer function

The transfer function [Link] in ImageJ is defined by a straight line [Wikipedia] whose formula is:
y = Ax + B with A is the slope and B is the y-intercept
Thus, two factors can be modified:

Let's see the influence of these two parameters on the image of Fig.1.

Fig. 1: Ramp image. This image is created from the command File > New Image... with the following paramters: (i) title: LUT , (ii) type: 8-bit , (iii) Fill: Ramp , and (iv)  size: 256x50.

Now, to display the transfer function, draw a horizontal line (Tool #5) and compute a plot profile with Analyze > Plot Profile.

[TODO Graph]
1.1 The y-intercept
If we modify the Y-intercept (B=50) by using  Process > Math > Macro... command and by typing the following formula:

v = v + 50


The new transfer function — computed from the plot profile of the horizontal line — is now...

Fig. 2: Transfer function of the form y = x - 50
In this case, a pixel value of 50 in the input image is displayed as a black (value = 0) pixel in the output. Consequently, the LUT is now darker than the original as shown in Fig. 3 and the input pixel value 255 now is equal to 200 (a light gray but not a white).

Fig.3: Output image
1.2. The slope
Reload the original LUT and type the following formula in  Process > Math > Macro...

v = v * 3.5

In this case (Fig. 4 and 5), the slope is equal to 3.5 leading to a variation of grays (gradient) from black to white restrained in the range of [60;130].

Fig. 4: Transfer function of equation  y =3.5x - 210.
... and the LUT appears as ...

Fig. 5: Output image corresponding to the transfer function of Fig. 4.


In conclusion, the brightness corresponds to the y-intercept and the contrast to the slope of the transfer function.

2. Transfer function and ImageJ

Our test image (Fig. 6) is a modified version of the clown available in the samples of ImageJ.
Fig. 6: Test image
The first thing to do is calculating the histogram in Analyze > Histogram or typing the shortcut Ctrl +  H (Fig.7)
Fig.7: Histogram of the image of Fig.1


Interestingly, all the pixel values are distributed in the range of 50 (Min value) and 178 (Max) with a mean value of 93.

 In ImageJ, go to Image > Adjust > Brightness/Contrast and a dialog window appears (Fig. 8). This panel is composed of a top graphics panel comprising the histogram of your image and a straight line - the transfer function - whose formula is equal to y = 1. x + 0, by default.

Fig.8: Brightness/Contrast dialog window

2.1. The sliders Brightness and Contrast
Here, we are only interested in the two last sliders Brightness and Contrast. By default, the pixel values of the input - original - image are the same as those of the output - displayed - image. By modifying the Y-intercept, the
2.2. What about the sliders Minimum and Maximum?
If you set the Minimum to 50 and the Maximum to 173, ImageJ can compute the slope and Y-intercept of the transfer function with this simple formula.

[TODO in MathML]

 This is also what is done if you click on the 'Auto' button.

Note: Don't forget to click on the 'Apply' button to apply the new transfer function to your image and then, close the B&C dialog window. 

... and now, the second part of this post where brightness and contrast can be modified by playing with the histogram.

<<  TOC : PreviousNext: Histogram >>

3. Other crazybiocomputing posts

Further readings are available in ...
  • Image Enhancement Series  [Link]
  • Image Processing TOC [Link]







No comments:

Post a Comment