Application of Histogram Equalization for Image Enhancement in Corrosion Areas

In this paper, an image enhancement algorithm is presented for identiﬁcation of corrosion areas and dealing with low contrast present in shadow areas of an image. This algorithm uses histogram equalization processing under the hue-saturation-intensity model. First of all, an etched image is transformed from red-green-blue color space to hue-saturation-intensity color space, and only the luminance component is enhanced. Then, part of the enhanced image is combined with the original tone component, followed by saturation and conversion to red-green-blue color space to obtain the enhanced corrosion image. Experimental results show that the proposed method signiﬁcantly improves overall brightness, increases contrast details in shadow areas, and strengthens identiﬁcation of corrosion areas in the image.


Introduction
In several applications, equipment made up of metallic material is widely used. Under the influence of the external environment, the metallic material will be corroded, causing the appearance of several features on the surface of the corrosion area, such as morphology, texture, grayscale, and color. e degree and type of corrosion in the material can be identified by analyzing these features. During visual inspection process, it is difficult to control the influence of the external environment, e.g. [1], light source, distance, and angle [2]. And, therefore, the quality of the corrosion image will be limited to a certain extent especially the corrosion picture inside the metal [3]. For subsequent detection and recognition of corrosion morphology, it is important to enhance this image [4].
At present, image enhancement algorithms mainly include single-scale Retinex (SSR) and multiscale Retinex (MSR) enhancement methods, which are based on the color sense consistency model [5][6][7], direct enhancement method aiming at pixel grayscale [8,9], homomorphic filtering enhancement method [10,11], enhancement method of defogging with respect to the dark channel priori theory [12,13], image enhancement algorithm based on wavelet transform, and histogram equalization algorithm [14,15]. Each of the above methods has its own advantages and can be used in relevant application scenarios.
e Retinex enhancement algorithm is put forward by Ma et al. [16][17][18]. is method can maintain brightness and details in an image and provide better enhancement for the gray area in the image [19]. Moreover, this method can effectively alleviate the halo phenomenon generated due to color restoration. However, the method is susceptible to color distortion, and the color of the image is different from the original color [20]. Color distortion also occurs when the method of direct processing of pixel values proposed by Mao et al. is used [12]. Although this method improves the dynamic range of image brightness, enhances the low-illumination image to some extent, and deals with Retinex halo artifact. e homomorphic filtering color image enhancement algorithm can improve the image brightness, but it does not deal with metal corrosion images. e dark channel defogging enhancement algorithm put forward by Wang et al. can enhance haze images [17], but it is only limited to images based on the dark channel principle [21]. Xu et al. used wavelet transform for image enhancement [18], and the results show that the wavelet transform can indeed enhance images. However, the image enhancement by this method is not significant. Hao et al. [22] address the problems in Retinex-based methods, such as less-effective image decomposition or strong imaging noise; it requires to carefully model the priori by a regularization term and usually makes the optimization process complicated. So the authors address these issues by proposing a novel Retinexbased low-light image enhancement method, in which the Retinex image decomposition is achieved in an efficient semidecoupled way. e experimental results show that the method has both higher visibility and better visual quality, which outperforms the state-of-the-art low light enhancement methods in terms of several objective and subjective evaluation metrics. Wang et al. [23] proposed a colored image correction method based on nonlinear functional transformation according to the illuminationreflection model and multiscale theory. Compared with the classic algorithm, the proposed algorithm can improve the adaptability of image enhancement in images with low illumination and other issues. Overall brightness and contrast of an image while reducing the impact of uneven illumination. e enhanced images appear clear, bright, and natural.
Image processing using a histogram equalization algorithm improves the contrast. However, when there are black parts in an image, enhancing the image will result in the loss of image features [19]. Hou and Liu proposed a metal corrosion image enhancement algorithm called dark details enhancement algorithm [9]. In this algorithm, by enhancing the "I" component in the HSI model, the overall brightness of the image and the recognition degree of the corrosion area can be enhanced. However, the enhancement effect on the hue and saturation of the image is not obvious, and the recognition degree of the corrosion area of the image is not evident.
To deal with the problems of the existing algorithms, this paper proposes a new algorithm that combines histogram equalization and dark detail algorithms. ese algorithms are chosen as they are known to have good image enhancement performance. Taking advantage of these algorithms and to minimize the image distortion as much as possible, we aim to maximize the information present in an image. e proposed image enhancement algorithm for metal corrosion areas is based on the HSI model [24]. e quality of the corrosion image will be limited by the external environmental factors present in an imaging channel. e purpose of this article is to solve this problem. e main contributions and novelty of this paper are as follows: (1) Aiming at the defects of the metal corrosion image, in order to effectively separate the features and background in the image, the novelty of this paper is to use the histogram equalization to process the metal corrosion image. e experiment shows that the effect is significant. (2) In this paper, wavelet transform and homomorphic filtering are combined to make the image have a uniform light background and lower distortion rate. At the same time, the combination of them makes the histogram equalization image enhancement better. Finally, a variety of algorithms are compared. (3) is paper uses histogram equalization and dark detail algorithms to increase the amount of information contained in the image while maintaining a low degree of distortion. e novelty lies in the optimization and adjustment of some parameters in the algorithm in order to better integrate these algorithms. e details of the algorithm proposed in this paper are as follows: firstly, the original corrosion image is converted from RGB color space to HSI color space, and the brightness component is extracted for enhancement. Secondly, the image is enhanced using histogram equalization and dark detail enhancement algorithms. Finally, the enhanced brightness component is restored to RGB color space together with the original saturation and hue components to obtain the enhanced corrosion image. Experimental results show that the enhanced image obtained using this algorithm greatly improves the recognition of corrosion area in the image and facilitates further analysis of corrosion and subsequent damage in metallic materials [25].
is paper is organized as follows: in Section 2, the theory behind this algorithm is elaborated, and the principles and implementation of the algorithm are described. Section 3 presents an analysis of the results obtained in the specific experimental environment. Section 4 concludes this paper [26].

Related Theory
In this paper, the HSI model is selected to extract the brightness component of the metal corrosion image. Subsequently, the brightness component is enhanced to improve image identification, which makes it easier to identify the corrosion area of metal. e dark detail enhancement algorithm proposed by Zhao and Sun and histogram equalization algorithm are combined to enhance the image. e best image output is chosen based on the image information entropy [27,28]. Figure 1 shows the flowchart of the proposed algorithm: the original corrosion image is converted from RGB color space to the HSI color model, followed by the application of histogram equalization and dark detail enhancement method to the component "I." e enhanced image is obtained by combining the enhanced "I" component with the original "H" and "S" components [6] and subsequent conversion to the RGB color space. e whole process is implemented using Matlab.

e HSI Model.
e HSI model has three components, H, S, and I, which are used to describe the color characteristics. ese components represent hue, saturation, and intensity or brightness, respectively. is model reflects the basic attributes of human perception of color.
erefore, the HSI model has been widely used in the image representation and processing system of the human visual perception system. In the HSI model, the color is only related to the "H" and "S" components [26]. Compared with the RGB model, in the HSI model, the correlation degree of each component is relatively small [29].
anks to this feature, good color image enhancement can be achieved, albeit with a few distortions [30]. is paper considers the conversion of HSI and RGB and proposes an improved algorithm based on histogram equalization. e formulas for converting the RGB model into HSI model are given by equations (1)-(4) as follows [31]:  Shock and Vibration In this paper, only the brightness component is enhanced, and after enhancement, it is combined with the original saturation and tonal components. e formulas for converting the HSI model into RGB model are given by equations (5)-(7) as follows [32]: 2.2. Histogram Equalization. Histogram equalization also known as histogram flattening is a nonlinear stretching of images and redistribution of image pixel values such that the number of pixel values in a certain gray range is roughly the same [26]. e image histogram is relatively flat by enhancing the contrast of the peak portion and reducing the contrast of the valley portions on both sides. In other words, the basic idea behind histogram equalization is that each gray level appears with the same frequency so that the probability of each gray level is evenly distributed, leading to a flat histogram. e image also becomes clear [7]. e theoretical formula of histogram equalization is as follows [25]: (1) Count the number of pixels in each gray level of the original input image. is number corresponding to the i th gray level is given by n i , where i � 0, 1, . . . , L − 1, and L is the total number of gray levels.
(2) Calculate the histogram of the original image, which is the probability density of each grayscale, given by P i (r i ) � n i /n, where n is the total number of pixels in the original image. (3) Calculate the cumulative distribution function as follows: which is an integer operator. Let g min � 0 and g max � L-1, this equation can be simplified into g k � INT [(L − 1) s k (r k ) + g min + 0.5]/((L − 1) × (I)). (5) According to the mapping relation between f k , i.e., the grayscale function of the original image and g k , modify the original grayscale to obtain an output image, whose histogram is approximately evenly distributed.
Figures 2(a) and 2(b) show the effect of histogram equalization on an image. It can be observed in Figures 2(c) and 2(d) that, after histogram equalization, the number of pixels is spread over all the range of gray levels, the image contrast is significantly improved, and the details in the image can be clearly seen.

Wavelet Adaptive Adjustment
2.3.1. Introduction to Wavelet Adaptive Adjustment. As shown in the example given in the previous subsection, histogram equalization enhances the whole image. However, a corrosion image with different scales and corrosion details cannot be effectively enhanced using only the equalization. Wavelet transforms with good localization properties in both the time spatial domain and frequency domain can be used for multiresolution analysis of signals. is paper uses this transform to make differential improvements to the image enhanced using the histogram equalization and modify the image background with different contrast scales. e flow of the wavelet adaptive adjustment algorithm is given in Figure 3. Firstly, the two-dimensional discrete wavelet transform is used to decompose the enhanced image obtained after histogram equalization, referred to as enhanced Figure 1. Secondly, nonlinear filtering operation is applied to the decomposed image group to obtain a filtered image group. Based on this image group, the weighting factor K j is calculated. Lastly, the image group is recombined based on K j , resulting in an enhanced image referred to as enhanced Figure 2.

Two-Dimensional Discrete Wavelet Decomposition.
In the process shown in Figure 3, two-dimensional discrete wavelets based on Matlab's fast decomposition algorithm [33] are used to decompose enhanced Figure 1. e wavelet decomposition series cannot be too large, as a large series leads to a higher computational complexity. Moreover, the illumination distribution characteristics cannot be fully reflected by the low-frequency wavelet coefficients, and as a result, the inhomogeneity of illumination cannot be effectively eliminated. However, if a small decomposition level is used, too much detailed information is included in the lowfrequency component, which results in a loss of image details. erefore, enhancement of the image details can be effectively carried out by choosing a decomposition level that 4 Shock and Vibration Shock and Vibration keeps the computational complexity low, but at the same time enhances the image details.
In this paper, the image is decomposed into two levels to meet the above requirements. In the proposed algorithm, wavelet adaptive adjustment is only a supplementary step, and under other conditions, the number of decomposition stages can be different, such as three or four. e relevant expression for carrying out the decomposition is shown in the following equation: e resulting image function f ∈ V j , {V j , j ∈ Z} gives a multiresolution analysis of the etched image. e first term on the right side of equation (8) is the low-band image, and the second term is the subimage with different frequency bands. e two-dimensional wavelet functions and scale functions are given by φ (x, y) and ϕ (x, y), respectively, D j− 1 is the low-frequency coefficient, and S n,j is the high-frequency coefficient. e subscript j represents the image level. Taking the algorithm in this paper as an example, the possible values of j are one and two. Figure 4 shows a schematic diagram of secondary decomposition wavelet image, where S 1,1 , S 2,1 , S 3,1 , and S 4,1 are four subregions based on level 1 image decomposition, and S 1,2 , S 2,2 , S 3,2 , and S 4,2 are secondary subregions based on level 2 decomposition of S 4,1 .

Nonlinear Filtering.
e nonlinear filtering operation is performed on the decomposed image group obtained in the previous group. e purpose of this operation is to correct the differences between contrast levels in the image background and to prepare for calculations in the next step. e operation modifies the brightness of each pixel in the decomposed image group. e modified value is the difference between maximum and minimum values in the neighborhood of each pixel point divided by the difference between the maximum and minimum values in the overall image. e relevant formula for this filtering operation is shown in the following equation: In the above equation, g max and g min are the maximum and minimum values in the overall image, respectively, and max(x j ) and min(x j ) are the maximum and minimum values in the 3 × 3 neighborhood around the filtering center point Q.

Global Contrast Weighting
Factor K j . In order to obtain the global contrast weighting factor K j , the global contrast K j global of the j level needs to be calculated first. It is calculated according to the following equation, where g j sum is the pixel sum of the filtered output image at the j level, and k 0 is the adjustment coefficient, which is generally equal to one.
Using the above equation, the global contrast-weighting factor K j of the j-level is calculated as follows:

Image Reconstruction.
Image reconstruction is performed according to the global contrast weighting factor K j and luminance coefficient L 0 using the formula shown in equation (12). e coefficient L 0 is determined by the overall brightness of the image, and it is fixed as one. Generally, as the reconstruction starts from the lowest level, the algorithm uses the second-level reconstruction first, followed by the first-level reconstruction [32].  Shock and Vibration Z x j , y j � L 0 · S 4,2 + 1 j�2 K j · S 1,2 + S 2,2 + S 3,2 . (12)

Block DCT (Discrete Cosine Transform) Homomorphic
Filtering. Since the captured image is affected by uneven illumination, a few parts of the image may have insufficient local brightness, causing the previously enhanced details to be submerged in the dark background.
Using the illumination reflection model and the enhanced Figure 2, Z(x j , y j ) can be characterized by two features: the total amount of light source, which is incident on the observed scene and the total amount of reflected light from the object in the scene. e incident light is relatively uniform and shows minor spatial variations, mainly in the low-frequency band. However, due to different natural and structural characteristics of an object, the reflected light shows the significant spatial variation in intensity, which is mainly reflected in the high-frequency band. erefore, to reduce the influence of uneven illumination, it is necessary to reduce the incident light and increase the reflection light. e homomorphic filtering algorithm consists of first taking the logarithm of the image obtained from the previous step and separating the incident and reflected light components. Fast Fourier transform (FFT) is applied to transform an image from the spatial domain into the frequency domain. Next, the appropriate homomorphic filtering function H(u, v) is selected to filter the image, and the filtered image is converted from the frequency domain to the spatial domain using inverse fast Fourier transform (IFFT). en, the enhanced luminance component image is obtained after taking the index. Finally, the enhanced luminance component image is obtained after taking the index, which eliminates the blocking effect caused by insufficient brightness and gives the final processed image.

Experimental Environment.
is paper proposes an image enhancement algorithm for observation of metal corrosion areas. e algorithm is mainly applied for image enhancement after pipeline image acquisition, and it is useful for detection and identification of subsequent corrosion morphology. erefore, in order to verify the enhancement effect of the algorithm on the metal pipe image, images of a metal pipe corroded due to exposure to natural environment are selected. e photos of the metal pipes are given in Figure 5, where the corrosion can be observed.

Experimental Procedure.
ree corrosion images with different corrosion patterns, uneven brightness, and low contrast in the corrosion areas are used for testing the performance of the proposed algorithm. ese images are shown in Figure 6. e pipeline corrosion images shown in Figure 6 are enhanced by dark detail enhancement algorithm, defogging algorithm, homomorphic filtering, histogram equalization, and the algorithm proposed in this paper. e Matlab software is used for plotting the histogram of the enhanced images. e information entropy values of these images are also calculated and compared.

Experimental Results.
e gray histograms of the three corrosion images enhanced by the dark detail enhancement algorithm, the defogging algorithm, the homomorphic filtering, the histogram equalization, and the proposed algorithm are shown in Figures 7-9. Table 1 gives the information entropy of the original images and the images enhanced using different enhancement algorithms shown in Figure 6. Table 2 is the mean and variance of the information entropy of an image set consisting of 20 corrosion images and the image set enhanced using different algorithms. Entropy is an important indicator to measure the amount of information present in an image. A large entropy value indicates the presence of a higher amount of information in an image, which means a better image quality.
Firstly, it can be observed from the original corrosion images shown in Figures 7-9 that their overall brightness tends to be low, due to which some details in parts of the images cannot be recognized and distinguished from the background. erefore, the corrosion degree detection of the tested area is directly affected due to low brightness. Figures 9(c) and 9(d) are the results after enhancement by the defogging algorithm and the homomorphic filtering. Although the information entropy values calculated after the use of these algorithms indicate improved image quality, some distortions occur. e data of Tables 1 and 2 show that all algorithms increase the information entropy of the image to different extents. According to the data, the proposed algorithm and the histogram equalization algorithm achieve the highest increase in the entropy values. By using the latter algorithm, the information entropy values of corrosion Figure 1 and corrosion Figure 3 are the highest among all the algorithms. However, it can be seen from Figures 7-9 that, after histogram equalization, the dark portions in the original images are enlarged, and consequently, they engulf the image details. e brightness of the images enhanced by the proposed algorithm is obviously improved, which can be seen from the gray histograms of the images. e enhanced images further show significant image improvement offered by the proposed algorithm. From the data in Table 2, it can be observed that the proposed algorithm obtains the highest mean entropy value and the lowest entropy variance. Tables 3 and 4 show the evaluation criteria of each method applied to the image. e average value reflects the brightness of the image. e larger the average value, the greater the image brightness and vice versa. e standard deviation reflects the degree of dispersion between the image pixel value and the average value. e larger the standard deviation, the better the image quality. Based on the images, histograms, and quantitative evaluation shown in this section, it can be concluded that the proposed algorithm has superior and consistent performance.     [24] 6.6281 0.0820 Defogging algorithm [17] 7.3701 0.0331 Homomorphic filtering [15] 6.8541 0.1929 Histogram [26] 7.5277 0.0313 Proposed algorithm 7.5281 0.0168

Conclusion
In this paper, an algorithm for enhancing metal corrosion images was proposed. e proposed algorithm used histogram equalization combined with dark detail enhancement algorithm, which resulted in enhanced metal corrosion image, and improved image quality and recognition degree. e algorithm makes it easier to observe the metal corrosion area and reduces the difficulty in carrying out research on metal products affected by corrosion, which can be important in practical applications. As the proposed algorithm combined two algorithms, the resulting computational complexity was high. Furthermore, image information entropy was the only metric used for selecting and evaluating the images, which can be simplistic for practical applications. erefore, the next step of our work is to select a set of image quality evaluation metrics to evaluate the algorithm performance in an all-round way and establish a direction for the optimization of the algorithm. At the same time, the logic and structure of the algorithm should be optimized to improve its real-time performance.

Data Availability
e data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
e authors declare that there are no conflicts of interest regarding the publication of this paper.