• Tidak ada hasil yang ditemukan

Gamma Correction

Dalam dokumen Digital Image Processing (Halaman 96-104)

4 Point Operations 4.1 Modifying Image Intensity

4.7 Gamma Correction

4Point Operations

Fig. 4.14 Histogram specification with a piecewise linear reference distribution. The target image IA(a), its histogram (d), and distribution functionPA(g);

the reference histogramhR(c) and the corresponding distri- butionPR(f); the modified imageIA (b), its histogram hA(e), and the resulting dis- tributionPA(h). Associ- ated mapping functionfhs(j).

Original image Modified image

Reference distribution

(piecewise linear) (a)IA (b)IA

(c)hR (d)hA (e)hA

(f)PR (g)PA (h)PA

0 50 100 150 200 255 50

100 150 200 255

a fhs(a)

(j)

4.7Gamma Correction

Original image Gaussian (σ= 50) Gaussian (σ= 100)

(a)IA (b)IG50 (c)IG100

Reference histogram pR(i)

Cumulative reference histogram PR(i)

(d) (e)

(f)hA (g)hG50 (h)hG100

(i)HA (j)HG50 (k)HG100

0 50 100 150 200 255 50

100 150 200 255

a fhs(a)

(l)

Fig. 4.15

Histogram matching: adjust- ing to a synthetic histogram.

Original imageIA(a), corre- sponding histogram (f), and cumulative histogram (i).

Gaussian-shaped reference histograms with centerμ= 128 andσ= 50 (d) andσ= 100 (e), respectively. Resulting images after histogram match- ing,IG50(b) andIG100(c) with the corresponding his- tograms (g, h) and cumulative histograms (j, k). Associated mapping functionfhs(l).

4.7.1 Why Gamma?

The term “gamma” originates from analog photography, where the relationship between the light energy and the resulting film density is approximately logarithmic. The “exposure function” (Fig. 4.17), specifying the relationship between the logarithmic light intensity and the resulting film density, is therefore approximatelylinear over a wide range of light intensities. The slope of this function within this linear range is traditionally referred to as the “gamma” of the photographic material. The same term was adopted later in televi-

75

4Point Operations

Fig. 4.16 Histogram matching: adjust- ing to a reference image. The target imageIA(a) is modified by matching its histogram to the reference imageIR(b), resulting in the new image IA (c). The corresponding histogramshA,hR,hA (d–f) and cumulative histograms HA,HR,PA(g–i) are shown.

Notice the good agreement between the cumulative his- tograms of the reference and adjusted images (h, i). Associ- ated mapping functionfhs(j).

Reference image Original image Modified image

(a)IR (b)IA (c)IA

(d)hR (e)hA (f)hA

(g)PR (h)PA (i)PA

0 50 100 150 200 255 50

100 150 200 255

a fhs(a)

(j)

sion broadcasting to describe the nonlinearities of the cathode ray tubes used in TV receivers, that is, to model the relationship be- tween the amplitude (voltage) of the video signal and the emitted light intensity. To compensate for the nonlinearities of the receivers, a “gamma correction” was (and is) applied to the TV signal once before broadcasting in order to avoid the need for costly correction measures on the receiver side.

Fig. 4.17 Exposure function of photo- graphic film. With respect to thelogarithmiclight in- tensityB, the resulting film densityDis approximately linearover a wide intensity range. The slope (ΔD/ΔB) of this linear section of the func- tion specifies the “gamma” (γ) value for a particular type of photographic material.

0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 0.5

1.0 1.5 2.0 2.5

0 0

D

B ΔD

ΔB

γ ΔDΔB

76

4.7Gamma Correction 4.7.2 Mathematical Definition

Gamma correction is based on the exponential function

fγ(a) =aγ, (4.27)

where the parameterγ R is called the gamma value. Ifa is con- strained to the interval [0,1], then—independent ofγ—the value of fγ(a) also stays within [0,1], and the function always runs through the points (0,0) and (1,1). In particular, fγ(a) is the identity func- tion forγ= 1, as shown inFig. 4.18. The function runsabovethe di- agonal for gamma valuesγ <1, andbelowit forγ >1. Controlled by a single continuous parameter (γ), the power function can thus “im- itate” both logarithmic and exponential types of functions. Within the interval [0,1], the function is continuous and strictly monotonic, and also very simple to invert as

a=fγ1(b) =b1, (4.28) since b1 = (aγ)1 = a1 = a. The inverse of the exponential functionfγ1(b) is thus again an exponential function,

fγ1(b) =f¯γ(b) =f1(b), (4.29) with the parameter ¯γ= 1.

1

0

0 1

a b=aγ

γ= 1 γ= 2

γ= 5 γ= 20 γ=201

γ= 15 γ= 12

Fig. 4.18

Gamma correction function fγ(a) =aγfora[0,1] and different gamma values.

4.7.3 Real Gamma Values

The actual gamma values of individual devices are usually specified by the manufacturers based on real measurements. For example, common gamma values for CRT monitors are in the range 1.8 to 2.8, with 2.4 as a typical value. Most LCD monitors are internally ad- justed to similar values. Digital video and still cameras also emulate the transfer characteristics of analog film and photographic cameras by making internal corrections to give the resulting images an accus- tomed “look”.

77

4Point Operations In TV receivers, gamma values are standardized with 2.2 for ana- log NTSC and 2.8 for the PAL system (these values are theoretical;

results of actual measurements are around 2.35). A gamma value of 1/2.20.45 is the norm for cameras in NTSC as well as the EBU7 standards. The current international standard ITU-R BT.7098 calls for uniform gamma values of 2.5 in receivers and 1/1.956 0.51 for cameras [76, 122]. The ITU 709 standard is based on a slightly modified version of the gamma correction (see Sec. 4.7.6).

Computers usually allow adjustment of the gamma value applied to the video output signals to adapt to a wide range of different monitors. Note, however, that the power function fγ() is only a coarse approximation to the actual transfer characteristics of any device, which may also not be the same for different color channels.

Thus significant deviations may occur in practice, despite the careful choice of gamma settings. Critical applications, such as prepress or high-end photography, usually require additional calibration efforts based on exactly measured device profiles (see Sec. 14.7.4).

4.7.4 Applications of Gamma Correction

Let us first look at the simple example illustrated in Fig. 4.19. As- sume that we use a digital camera with a nominal gamma valueγc, meaning that its output signalsrelates to the incident light intensity Las

S=Lγc. (4.30)

Fig. 4.19 Principle of gamma correction.

To compensate the output signalSproduced by a camera with nominal gamma valueγc, a gamma correction is applied with ¯γc= 1c. The corrected signalSis proportional to the received light intensityL.

Light

Camera Gamma

correction

Corrected signal

S=Lγc

L SL

γc ¯γc= 1

γc

f¯

γc(S)

To compensate the transfer characteristic of this camera (i.e., to obtain a measurement S that is proportional to the original light intensity L), the camera signal S is subject to a gamma correction with the inverse of the camera’s gamma value ¯γc= 1c and thus

S=fγ¯c(S) =S1c. (4.31) The resulting signal

S=S1c =

Lγc1c

=L(γcγc1)=L1

is obviously proportional (in theory even identical) to the original light intensity L. Although this example is quite simplistic, it still demonstrates the general rule, which holds for output devices as well:

7 European Broadcast Union (EBU).

8 International Telecommunications Union (ITU).

78

4.7Gamma Correction The transfer characteristic of an input or output device with

specified gamma valueγis compensated for by a gamma cor- rection with ¯γ= 1.

In the aforementioned, we have implicitly assumed that all values are strictly in the range [0,1], which usually is not the case in practice.

When working with digital images, we have to deal with discrete pixel values, for example, in the range [0,255] for 8-bit images. In general, performing a gamma correction

b←fgc(a, γ),

on a pixel valuea∈[0, amax] and a gamma valueγ >0 requires the following three steps:

1. Scalealinearly to ˆa∈[0,1].

2. Apply the gamma correction function to ˆa: ˆb←ˆaγ. 3. Scale ˆb∈[0,1] linearly back tob∈[0, amax].

Formulated in a more compact way, the corrected pixel value b is obtained from the original valueaas

b a

amax γ

·amax. (4.32)

Figure 4.20illustrates the typical role of gamma correction in the digital work flow with two input (camera, scanner) and two output devices (monitor, printer), each with its individual gamma value.

The central idea is to correct all images to be processed and stored in a device-independent, standardized intensity space.

Processing Storage γc= 1.3

¯ γc=1.31

γs= 1.9

¯ γs= 1.91

γm= 2.6

¯ γm= 2.61

γp= 3.0

¯ γp=3.01

Fig. 4.20

Gamma correction in the digi- tal imaging work flow. Images are processed and stored in a “linear” intensity space, where gamma correction is used to compensate for the transfer characteristic of each input and output device. (The gamma values shown are exam- ples only.)

4.7.5 Implementation

Program 4.4 shows the implementation of gamma correction as an ImageJ plugin for 8-bit grayscale images. The mapping function fgc(a, γ) is computed as a lookup table (Fgc), which is then applied to the image using the methodapplyTable()to perform the actual point operation (see also Sec. 4.8.1).

79

4Point Operations

Prog. 4.4 Implementation of gamma cor- rection in therun()method of an ImageJ plugin. The corrected intensity valuesb are only computed once and stored in the lookup table Fgc(line 15). The gamma valueGAMMAis constant. The actual point operation is per- formed by calling the ImageJ methodapplyTable(Fgc)on the image objectip(line 18).

1 public void run(ImageProcessor ip) {

2 // works for 8-bit images only 3 int K = 256;

4 int aMax = K - 1;

5 double GAMMA = 2.8;

6

7 // create and fill the lookup table:

8 int[] Fgc = new int[K];

9

10 for (int a = 0; a < K; a++) {

11 double aa = (double) a / aMax; // scale to[0,1]

12 double bb = Math.pow(aa, GAMMA); // power function 13 // scale back to[0,255]:

14 int b = (int) Math.round(bb * aMax);

15 Fgc[a] = b;

16 }

17

18 ip.applyTable(Fgc); // modify the image

19 }

4.7.6 Modified Gamma Correction

A subtle problem with the simple power function fγ(a) =aγ (Eqn.

(4.27)) appears if we take a closer look at theslope of this function, expressed by its first derivative,

fγ(a) =γ·a(γ1), which fora= 0 has the values

fγ(0) =

⎧⎪

⎪⎩

0 forγ >1, 1 forγ= 1,

forγ <1.

(4.33)

The tangent to the function at the origin is thus horizontal (γ >

1), diagonal (γ= 1), or vertical (γ <1), with no intermediate values.

Forγ <1, this causes extremely high amplification of small intensity values and thus increased noise in dark image regions. Theoretically, this also means that the power function is generally not invertible at the origin.

A common solution to this problem is to replace the lower part (0≤a≤a0) of the power function by alinearsegment with constant slope and to continue with the ordinary power function for a > a0. The resulting modified gamma correction function,

f¯γ,a0(a) =

s·a for 0≤a≤a0,

(1 +d)·aγ−d fora0< a≤1, (4.34)

with s= γ

a0(γ−1) +a(10γ) and d= 1

aγ0(γ−1) + 11 (4.35) thus consists of alinearsection (for 0≤a≤a0) and anonlinear sec- tion (fora0 < a≤1) that connect smoothly at the transition point 80

4.7Gamma Correction

f¯γ,a

0(a)

a f¯γ,a

0(a)

a

(a)γ= 0.5,a0= 0.2 (b)γ= 2.0,a0= 0.2

Fig. 4.21

Modified gamma correction.

The mapping ¯fγ,a

0(a) consists of a linear segment with fixed slopesbetweena = 0 and a =a0, followed by a power function with parameterγ (Eqn. (4.34)). The dashed lines show the ordinary power functions for the same gamma values.

a=a0. The linear slope s and the parameterd are determined by the requirement that the two function segments must have identical values as well as identical slopes (first derivatives) ata=a0 to pro- duce a continuous function. The function in Eqn. (4.34) is thus fully specified by the two parametersa0 andγ.

Figure 4.21shows two examples of the modified gamma correction f¯γ,a0() with valuesγ= 0.5 andγ= 2.0, respectively. In both cases, the transition point is ata0 = 0.2. For comparison, the figure also shows the ordinary gamma correction fγ(a) for the same gamma values (dashed lines), whose slope at the origin is (Fig. 4.21(a)) and zero (Fig. 4.21(b)), respectively.

Gamma correction in common standards

The modified gamma correction is part of several modern imaging standards. In practice, however, the values of a0 are considerably smaller than the ones used for the illustrative examples inFig. 4.21, and γ is chosen to obtain a good overall match to the desired cor- rection function. For example, the ITU-BT.709 specification [122]

mentioned in Sec. 4.7.3 specifies the parameters

γ= 1

2.222 0.45 and a0= 0.018, (4.36) with the corresponding slope and offset values s = 4.50681 and d= 0.0991499, respectively (Eqn. (4.35)). The resulting correction function ¯fITU(a) has a nominal gamma value of 0.45, which corre- sponds to the effective gamma value γeff = 1/1.956 0.511. The gamma correction in the sRGB standard [224] is specified on the same basis (with different parameters; see Sec. 14.4).

Figure 4.22shows the actual correction functions for the ITU and sRGB standards, respectively, each in comparison with the equiv- alent ordinary gamma correction. The ITU function (Fig. 4.22(a)) withγ= 0.45 anda0= 0.018 corresponds to an ordinary gamma cor- rection with effective gamma valueγeff = 0.511 (dashed line). The curves for sRGB (Fig. 4.22(b)) differ only by the parameters γ and a0, as summarized inTable 4.1.

81

4Point Operations

Fig. 4.22 Gamma correction func- tions specified by the ITU-R BT.709 (a) and sRGB (b) standards. The continu- ous plot shows the mod- ified gamma correction with the nominalγvalues and transition pointsa0.

f¯ITU(a)

a

f¯sRGB(a)

a

(a)γ0.450,a0= 0.018 (b)γ0.417,a0= 0.0031308 Table 4.1

Gamma correction pa- rameters for the ITU and sRGB standards based on the modified mapping in Eqns. (4.34) and (4.35).

Standard

Nominal gamma value

γ a0 s d

Effective gamma value

γeff ITU-R BT.709 1/2.2220.450 0.018 4.50 0.099 1/1.9560.511 sRGB 1/2.4000.417 0.0031308 12.92 0.055 1/2.2000.455

Inverting the modified gamma correction

To invert the modified gamma correction of the form b = ¯fγ,a0(a) (Eqn. (4.34)), we need the inverse of the function ¯fγ,a0(), which is again defined in two parts,

f¯γ,a10(b) =

b/s for 0≤b≤s·a0, b+d

1+d

1

fors·a0< b≤1. (4.37) sanddare the quantities defined in Eqn. (4.35) and thus

a= ¯fγ,a10f¯γ,a0(a)

fora∈[0,1], (4.38) with the same value γ being used in both functions. The inverse gamma correction function is required in particular for transforming between different color spaces if nonlinear (i.e., gamma-corrected) component values are involved (see also Sec. 14.2).

Dalam dokumen Digital Image Processing (Halaman 96-104)