# Write about histogram specification.

1 day ago

### Histogram Matching (Specification):

Histogram equalization automatically determines a transformation function that seeks to produce an output image that has a uniform histogram.When automatic enhancement is desired, this is a good approach because the results from this technique are predictable and the method is simple to implement. In particular, it is useful sometimes to be able to specify the shape of the histogram that we wish the processed image to have.The method used to generate a processed image that has a specified histogram is called histogram matching or histogram specification.

### Development of the method:

Let us return for a moment to continuous gray levels r and z (considered continuous random variables), and let p_{r}(r) and p_{z}(z) denote their corresponding continuos probability density functions. In this notation, r and z denote the gray levels of the input and output (processed) images, respectively.We can estimate p_{r}(r) from the given input image, while p_{z}(z) is the specified probability density function that we wish the output image to have.

Let s be a random variable with the property

where w is a dummy variable of integration.We recognize this expression as the continuos version of histogram equalization. Suppose next that we define a random variable z with the property

where t is a dummy variable of integration. It then follows from these two equations that G(z)=T(r) and, therefore, that z must satisfy the condition

The transformation T(r) can be obtained once p_{r}(r) has been estimated from the input image. Similarly, the transformation function G(z) can be obtained because p_{z}(z) is given. Assuming that G^{-1} exists and that it satisfies conditions (a) and (b) in the histogram equalization process, the above three equations show that an image with a specified probability density function can be obtained from an input image by using the following procedure:

- Obtain the transformation function T(r).
- To obtain the transformation function G(z).
- Obtain the inverse transformation function G
^{-1} - Obtain the output image by applying above to all the pixels in the input image.

The result of this procedure will be an image whose gray levels, z, have the specified probability density function p_{z}(z). Although the procedure just described is straightforward in principle, it is seldom possible in practice to obtain analytical expressions for T(r) and for G^{-1.} Fortunately, this problem is simplified considerably in the case of discrete values.The price we pay is the same as in histogram equalization,where only an approximation to the desired histogram is achievable. In spite of this, however, some very useful results can be obtained even with crude approximations.

Where n is the total number of pixels in the image, n_{j} is the number of pixels with gray level r_{j}, and L is the number of discrete gray levels. Similarly, the discrete formulation is obtained from the given histogram p_{z} (z_{i}), i=0, 1, 2,……, L-1, and has the form

As in the continuos case, we are seeking values of z that satisfy this equation.The variable v_{k} was added here for clarity in the discussion that follows. Finally, the discrete version of the above Eqn. is given by

or

### Implementation:

We start by noting the following: (1) Each set of gray levels {r_{j}} , {s_{j}}, and {z_{j}}, j=0, 1, 2, p , L- 1, is a one-dimensional array of dimension L X 1. (2) All mappings from r to s and from s to z are simple table lookups between a given pixel value and these arrays. (3) Each of the elements of these arrays, for example, s_{k}, contains two important pieces of information: The subscript k denotes the location of the element in the array, and s denotes the value at that location. (4) We need to be concerned only with integer pixel values. For example, in the case of an 8-bit image, L=256 and the elements of each of the arrays just mentioned are integers between 0 and 255.This implies that we now work with gray level values in the interval [0, L-1] instead of the normalized interval [0, 1] that we used before to simplify the development of histogram processing techniques.

In order to see how histogram matching actually can be implemented, consider Fig. 5(a), ignoring for a moment the connection shown between this figure and Fig. 5(c). Figure 5(a) shows a hypothetical discrete transformation function s=T(r) obtained from a given image. The first gray level in the image, r_{1} , maps to s_{1} ; the second gray level, r_{2} , maps to s_{2} ; the kth level r_{k} maps to s_{k}; and so on (the important point here is the ordered correspondence between these values). Each value s_{j} in the array is precomputed, so the process of mapping simply uses the actual value of a pixel as an index in an array to determine the corresponding value of s.This process is particularly easy because we are dealing with integers. For example, the s mapping for an 8-bit pixel with value 127 would be found in the 128th position in array {s_{j}} (recall that we start at 0) out of the possible 256 positions. If we stopped here and mapped the value of each pixel of an input image by the

### Fig.5. (a) Graphical interpretation of mapping from r_{k} to s_{k} via T(r). (b) Mapping of z_{q} to its corresponding value v_{q} via G(z) (c) Inverse mapping from s_{k} to its corresponding value of z_{k}.

** **

method just described, the output would be a histogram-equalized image. In order to implement histogram matching we have to go one step further. Figure 5(b) is a hypothetical transformation function G obtained from a given histogram p_{z}(z). For any z_{q} , this transformation function yields a corresponding value v_{q}. This mapping is shown by the arrows in Fig. 5(b). Conversely, given any value v_{q}, we would find the corresponding value z_{q} from G^{-1}. In terms of the figure, all this means graphically is that we would reverse the direction of the arrows to map v_{q} into its corresponding z_{q}. However, we know from the definition that v=s for corresponding subscripts, so we can use exactly this process to find the z_{k} corresponding to any value s_{k} that we computed previously from the equation s_{k} = T(r_{k}) .This idea is shown in Fig.5(c).

Since we really do not have the z’s (recall that finding these values is precisely the objective of histogram matching),we must resort to some sort of iterative scheme to find z from s.The fact that we are dealing with integers makes this a particularly simple process. Basically, because v_{k} = s_{k}, we have that the z’s for which we are looking must satisfy the equation G(z_{k})=s_{k}, or (G(z_{k})- s_{k})=0. Thus, all we have to do to find the value of z_{k} corresponding to s_{k} is to iterate on values of z such that this equation is satisfied for k=0,1,2,… , L-1. We do not have to find the inverse of

G because we are going to iterate on z. Since we are dealing with integers, the closest we can get to satisfying the equation (G(z_{k})-s_{k})=0 is to let z_{k}= for each value of k, where is the smallest integer in the interval [0, L-1] such that

Given a value s_{k}, all this means conceptually in terms of Fig. 5(c) is that we would start with and increase it in integer steps until Eq is satisfied, at which point we let repeating this process for all values of k would yield all the required mappings from s to z, which constitutes the implementation of Eq. In practice, we would not have to start with each time because the values

of sk are known to increase monotonically. Thus, for k=k+1, we would start with and increment in integer values from there.

###### Raju Singhaniya

Oct 15, 2021