The proposed method enhances an image with a special attention to the dark region of that image. This method can be applied on both gray and color images. For color images, color space conversion is needed because direct RGB color processing cannot preserve the original color; rather, it produces undesirable effect on the output image. Different kinds of color spaces are available such as HSV, HSI, Lab, and Luma. In the proposed method, we have used HSV color space to process the image due to its additive advantages. The advantages which HSV provides are delineated below [23].
-
In HSV color model, V (luminance) and color information (hue and saturation) are decoupled.
-
Color relationships of HSV color model are described more meticulously than RGB color model.
-
We can easily transform RGB color model to HSV color model and vice versa.
After applying the enhancement on V channel, the image is converted back to RGB. The whole enhancement process consists of two major steps: (1) preprocessing and (2) enhancement. These two are discussed in the following sub-sections.
2.1 Preprocessing
The proposed algorithm divides an image histogram into several parts based on the peaks and valleys, and then, each individual part is processed separately. However, an image, especially a dark image, contains noise (random fluctuation of intensities). Due to the presence of noise, many insignificant local peaks and valleys are n in the image histogram, which may lead to partition the histogram into too many parts and thus distract the whole process from getting the desired effect. For a good enhancement, these noise should be removed. Smoothing filter helps us to get the desired resullt in this case. We apply Gaussian smoothing filter [27] as presented in Eq. 1.
$$ G(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{x^{2}}{2\sigma^{2}}} $$
(1)
Here, σ represents standard deviation. In an image, specifically in a dark image, some intensities might exist at very few number of pixels that are not important to visualize the objects in that image. Hence, we propose to merge the histogram bins of such unimportant intensities with the neighboring bins so that our later procedures get more room to process the histogram segments.
We use Algorithm 1 to dynamically calculate a threshold (τ) from the input histogram and to find such insignificant intensities. τ gives a level for the accumulation of a bin justifying whether the presence of the corresponding intensity is significant or not. Algorithm 2 scans every bin of the histogram and compares it with τ. If the accumulation is less than τ, the accumulation is added to the next bin’s accumulation. Thus, we dissolve the insignificant bins in a histogram.
2.2 Enhancement
We are usually more interested in edges of an image as compared to smooth regions. Hence, edge and non-edge regions should be treated separately. To do so, we apply the Sobel operator to find the absolute gradient magnitude at each pixel of the given image (Iin) and then use a threshold on the values to approximate the regions (pixels) corresponding to edges (I
E
) and non-edges (I
NE
). After separating edge and non-edge images, we calculate histograms H
E
and H
NE
for these two images, respectively. We then find the segments S
E
and S
NE
from H
E
and H
NE
, respectively. S
E
and S
NE
are then used to generate two desired histograms \(\left (\text {namely}\, H_{E}^{\prime }\, \text {and}\, H_{NE}^{\prime }\right)\): one is to enhance edges and another for enhancing smooth regions. These two histograms are merged together to yield the final desired histogram, which is then used in histogram specification step to enhance the whole image. Algorithm 3 and Fig. 2 show our overall procedure for dark image enhancement.
From the preprocessing step, we obtain prominent peaks and valleys for the histogram of a given image. These peaks and valleys are used to identify a set of segments where a segment is defined as follows:
Definition-1 segment: Histogram bins between two valleys are considered as a segment where valleys (V) are defined in Eq. 2.
$$ V = \left\{i | x_{i-1} > x_{i} < x_{i+1}\right\} $$
(2)
where x
i
is the accumulation of the ith bin of the histogram. Formally, a segment (S
i
) is a portion of a histogram that lies between the two valleys V
i
and Vi+1. In Fig. 3, s1, s2, s3, s4, and s5 are segments.
For enhancement, we perform two types of operations for each of these segments of the histogram: First, segment reallocation and second, gray level transformation within segment. Detail of these two steps are described in the following sub-sections.
2.2.1 Segment reallocation
The objective of relocating the segments is to transform a set of gray levels from the dark region of the image to the relatively brighter region. Figure 4 illustrates the shifting of segments from one location to another location of the histogram.
These segments are shifted based on the shifting distance D. This shifting distance is dynamically calculated for each segment using Eq. 3.
$$ D(i) = \left \lceil \frac{x_{i}}{\sum_{i=0}^{N-1}x_{i}}\times N \right \rceil $$
(3)
where N = total number of segments, D(i) = shifting distance of ith segment, x
i
= accumulation of ith segment.
For example, if the total number of accumulation =100, accumulation of the ith segment =10 and total number of segments =50, then the shifting distance will be D(i)=(10/100)×50=5. So, new ending position of this segment will be Vi+1+5. And thus, the width of a segment depends on the number of pixels it contains. Here, the segments containing more pixels will be allocated more gray levels, which are expected for enhancement.
After shifting each segment, there exist several empty bins at the end of the histogram. We distribute these empty bins to all the segments using Eq. 4
$$ L_{i} = l_{i} + \frac{l_{i}}{\theta}\times (255 - \theta) $$
(4)
where l
i
= width of the ith segment, L
i
= resultant width of the ith segment, θ = ending bin position of the last segment. Thus, it also gives more space to perform intra-segment transformation.
2.2.2 Intra-segment transformation
By shifting the segments, we transform the intensities of a set of pixels as a whole. It enhances the contrast among the bins in different segments. However, we need to enhance within-segment contrasts for getting a better looking image. For this reason, we transform the intensities of the pixels within a segment which is performed using Eq. 5. The result of such transformation is shown in Fig. 5.
$$ T(i) = \frac{\Omega (i)}{\sum_{j=s}^{k}\Omega(j)}\times {L} $$
(5)
where T(i) = transformed intensity of ith bin, Ω(i) = accumulation of ith bin, s = starting bin position of the segment, k = last bin position of the segment, L = width of the corresponding segment (from Eq. 4).
2.2.3 Histogram specification
By performing the segment reallocation and intra-segment transformation, we get the the transformed histograms for both edge and non-edge images. The desired histogram is obtained by combining these two histograms which is used to perform histogram specification.
Here, a gray level, i, of the input image is mapped to another gray level, d, such that
$$ C_{\text{in}}(i) = C_{\text{desired}}(d) $$
(6)
where Cin(i) and Cdesired(d) represent the cumulative distribution functions calculated from the input image and the desired histogram, respectively. In other words, we seek the gray level, d, for which
$$ d= C_{\text{desired}}^{-1} \left(C_{\text{in}}(i)\right) $$
(7)
We apply Eq. 7 on every gray level of the input image to get the enhanced image. The output image is transformed back to RGB if the original image is RGB.