When the color in the image is rich and evenly distributed, the gray world method can be used to obtain an ideal correction result. However, for some specific scenes, such as the existence of a large area of a single color in the image, the premise of the gray world method assumption is no longer satisfied, and the corrected image will produce a significant color deviation. The richer the image color, the more accurate the color reproduction during calibration. According to the definition of entropy, image entropy can be used to measure the richness of image color. The richer the image color, the larger the image entropy; conversely, the less the color in the image, the smaller the image entropy. Applying the physical meaning of image entropy to the algorithm, firstly, the image is evenly segmented, the entropy values of different sub-blocks are different, and the weights are assigned according to the sub-block entropy value, thereby reducing the influence of a single-color block. Based on the image entropy theory, the gray world algorithm is improved, and the application range of the algorithm is expanded. First, the histogram equalization processing is performed on the R, G, and B channels of the image to improve the overall contrast. After the equalization process, the color cast of the color cast image has been weakened and the image contrast is deepened [13].
When the image is chunked, the choice of partition size is important. Considering the distribution of the pixel level, the image is divided into sub-blocks Tij(1 ≤ i ≤ m, 1 ≤ j ≤ n)of 16 × 16 size, which are divided into n × m image blocks, and the block mode is as shown in Fig. 1. The three-channel image entropy of the image sub-blocks R, G, and B is calculated by using Eq. (1), which are denoted as \( {H}_{ij}^{\mathrm{R}} \), \( {H}_{ij}^{\mathrm{G}} \), and \( {H}_{ij}^{\mathrm{B}} \), and the mean value is taken as the image entropy of the image block [14]:
$$ {E}_{ij}=\left({H}_{ij}^{\mathrm{R}}+{H}_{ij}^{\mathrm{G}}+{H}_{ij}^{\mathrm{B}}\right)/3 $$
(1)
The larger the entropy value of the image block and the richer the color of the image block, the more accurate the color reduction during correction, and the image obtained when the gray world method is used for correction is also the expected image. Therefore, in order to reduce the influence of a single-color block on image correction, a color-rich image block is given a higher weight level, and a color-only image block is given a lower weight level. The concept of image entropy is used to measure the color richness of sub-blocks, and weights are assigned according to their size. The larger the entropy value of the image block, the larger the weight of the allocation; conversely, the smaller the entropy value of the image block, the smaller the weight assigned to it. Therefore, after calculating the image entropy of all sub-blocks, the sub-block weight value is calculated by normalizing the image entropy, and the calculation formula is [15]:
$$ {W}_{ij}=\frac{E_{ij}}{\sum_{i=1}^m{\sum}_{j=1}^n{E}_{ij}} $$
(2)
Among them, Wij is the corresponding weight of any image block Tij(1 ≤ i ≤ m, 1 ≤ j ≤ n), and Eij is the image entropy of the sub-block. The average values of the three channels R, G, and B of each image block are counted and recorded as \( \overline{\ {\mathrm{R}}_{ij}} \), \( \overline{G_{ij}} \), and \( \overline{B_{ij}} \). According to the weight value of the sub-block entropy value, the mean R, G, and B channel values [16] of the whole image are calculated:
$$ \left\{\begin{array}{c} EW{\_}_{\overline{R}}={\sum}_{i=1}^m{\sum}_{j=1}^n{W}_{ij}\times \overline{{\mathrm{R}}_{ij}}\\ {} EW{\_}_{\overline{G}}={\sum}_{i=1}^m{\sum}_{j=1}^n{W}_{ij}\times \overline{{\mathrm{G}}_{ij}}\\ {}E\_{W}_B={\sum}_{i=1}^m{\sum}_{j=1}^n{W}_{ij}\times \overline{\mathrm{B}}\end{array}\right. $$
(3)
After obtaining the weighted mean value of the entropy values of the R, G, and B channels, the average value of the three-channel entropy is taken as the average gray value of the image, namely:
$$ \mathrm{Gray}=\left( EW{\_}_{\overline{R}}+ EW{\_}_{\overline{G}}+E\_{W}_B\right)/3 $$
(4)
The Von Kries diagonal model is applied to update the R, G, and B components of each pixel in the image, and corrects the entire image, and adjusts the corrected pixels to a displayable range [0, 255].
$$ \left\{\begin{array}{c}{R}^{\prime }=\left\{\begin{array}{c}R\ast {R}_{\mathrm{Gain}}\to R\ast {R}_{\mathrm{Gain}}<255\\ {}255\to R\ast {R}_{\mathrm{Gain}}>255\end{array}\right\}\\ {}{R}^{\prime }=\left\{\begin{array}{c}G\ast {G}_{\mathrm{Gain}}\to G\ast {G}_{\mathrm{Gain}}<255\\ {}255\to G\ast {G}_{\mathrm{Gain}}>255\end{array}\right\}\\ {}{R}^{\prime }=\left\{\begin{array}{c}B\ast {B}_{\mathrm{Gain}}\to B\ast {B}_{\mathrm{Gain}}<255\\ {}255\to B\ast {B}_{\mathrm{Gain}}>255\end{array}\right\}\end{array}\right. $$
(5)
For imaging devices such as cameras, there is a large difference between the colors of images acquired under different lighting conditions. In the normal color temperature environment, the acquired image has no color cast, which is basically consistent with human visual perception. However, when the color temperature is high, the image is blue overall, and when the color temperature is low, the image is yellowish overall. Figure 2 shows the imaging of the same scene at different color temperatures, and it can be seen that there is a significant difference between the two.
When white balance correction is performed on images acquired under different lighting conditions, if the image is always corrected with a uniform coefficient, it is impossible to obtain a better correction result under various conditions. Therefore, before correcting the image, it is necessary to first detect the color cast of the image to determine whether there is color cast. If it is a color cast image, its type needs to be determined. After knowing the specific color cast of the image, the image can be processed with different coefficients in a targeted manner. According to this idea, an automatic white balance algorithm based on image color cast detection is proposed.
When measuring the degree of deviation between two colors, for the commonly used RGB color space, the difference between the two colors calculated does not correctly represent the true difference between the two colors that people actually perceive. According to the study of color space theory, the CIE Lab color space is close to the perception characteristics of the human visual system, and the distance between the colors calculated by the space is in line with people’s actual perception. Therefore, the CIE Lab color space is used to examine the color cast of the image.
The color cast of the image is related to the chromaticity distribution characteristics and the chromaticity mean of the image. When there is a color cast in the image, the two-dimensional histogram distribution on the ab chromaticity coordinate plane is concentrated, which is basically a single peak. At the same time, the larger the chromaticity mean, the larger the color deviation. In contrast, if the two-dimensional histogram distribution is more scattered and there are obvious multi-peaks, the color cast is weakened. Therefore, the concept of equivalent circle is introduced, and the ratio of image mean chromaticity to chromaticity center distance is used to measure the degree of color shift of the image. The color cast factor K is defined as the ratio of the average chromaticity D of the image to the center distance C of the chromaticity. The calculation method is as shown in Eq. (6). The average chromaticity D and the chromatic center distance C are as shown in Eqs. (7, 8), respectively.
$$ D=\sqrt{d_a^2+{d}_b^2},{d}_a=\frac{\sum_{i=1}^M{\sum}_{j=1}^Na}{MN},{d}_b=\frac{\sum_{i=1}^M{\sum}_{j=1}^Nb}{MN} $$
(7)
$$ C=\sqrt{C_a^2+{C}_b^2},{C}_a=\frac{\sum_{a= mina}^{\max a}\left|a-{d}_a\right|}{MN},{C}_b=\frac{\sum_{a= minb}^{\max b}\left|b-{d}_b\right|}{MN}P(b) $$
(8)
Among them, M and N are the width and height of the image, respectively, in units of pixels. P(a) and P(b) are the corresponding histograms of the positions a and b, respectively. On the ab chromaticity plane, the center coordinate of the equivalent circle is (da, db), the radius is C, and the distance from the center of the equivalent circle to the origin of the central axis of the ab chromaticity plane (a = 0, b = 0) is D. Within a certain range of the equivalent circle, the image is considered to have no color shift. If it exceeds the range, it is considered to have a color shift, and the farther the deviation is, the larger the color deviation is. The threshold of the color cast factor is Kfold. If K > Kfold, the image is considered to have a color cast. Otherwise, it is considered to be colorless. Generally, Kfold is taken as 1.
When the picture has a color cast, the image color cast is judged by the specific position of the equivalent circle on the ab chromaticity plane. The color cast grade is divided into reddish, bluish, greenish, and yellowish. When da ≥ 0, − da ≤ db ≤ k1da, the picture is reddish. When da < 0, da ≤ db ≤ k2da, the picture is greenish. When db < 0, |da| < 0, |da| < |db|, the picture is bluish. In other cases, the picture is yellowish. The schematic diagram of the color cast is shown in Fig. 3. By evaluating and analyzing multiple images, k1 is taken as 2 and k2 is − 2.
Through the color cast detection, it has been possible to determine the color cast of the image. Therefore, in the white balance correction, different correction coefficients can be used to correct the image according to the specific color cast. In the correction, the image is first histogram equalized. In the RGB color space, the R, G, and B channels are respectively histogram equalized to obtain the equalized image, and the image color cast is initially weakened. The image is then converted from the RGB color space to the YCbCr color space, and the data (YHisp,CrHisp, CbHisp) after the histogram equalization of the image is obtained. All pixel points from which Eq. (9) is satisfied are found.
$$ \left\{\begin{array}{c}{Y}_{Hist}\ge 210\\ {}-3\le {Cr}_{Hisp},{Cb}_{Hisp}\le +3\end{array}\right. $$
(9)
In the pixel point satisfying the Formula (9), the highest luminance pixel point \( \left({Y}_{\mathrm{Hist}}^{\mathrm{bright}},{Cr}_{\mathrm{Hist}}^{\mathrm{bright}},{Cb}_{\mathrm{Hist}}^{\mathrm{bright}}\right) \) is found by the maximum value YHist and the value closest to zero CrHisp, CbHisp, and the average value \( \left({Y}_{\mathrm{Hist}}^{\mathrm{avg}},{Cr}_{\mathrm{Hist}}^{\mathrm{avg}},{Cb}_{\mathrm{Hist}}^{\mathrm{avg}}\right) \) satisfying all the pixel points of the Eq. (9) is calculated. Then, all the pixels satisfying the Eq. (10) are found from the histogram-equalized data of the image.
$$ \left\{\begin{array}{c}{Y}_L\le {Y}_{\mathrm{Hist}}\le {Y}_H\\ {}{Cr}_L\le {Cr}_{\mathrm{Hist}}\le {Cr}_H\\ {}{Cb}_L\le {Cb}_{\mathrm{Hist}}\le {Cb}_H\end{array}\right. $$
(10)
Among them, YL and YHY are respectively the minimum and maximum values selected between YH and \( {Y}_{\mathrm{Hist}}^{\mathrm{avg}},{Cr}_L \) and CrH are respectively the minimum and maximum values selected between \( {Cr}_{\mathrm{Hist}}^{\mathrm{bright}} \) and \( {\mathrm{Cr}}_{\mathrm{Hist}}^{\mathrm{avg}} \), and CbL and CbH are the same.
For pure white points (255, 255, 255), the corresponding YCbCr value is (255, 0, 0). Therefore, the larger the Y value, the closer the CbCr value is to the pixel point of 0, that is, the closer it is to the white point. The white point in the image is initially selected by the conditional limitation of Eq. (9). Equation (10) further severely selects the conditions for the white point and removes some of the pixel points from the white point just selected, and the remaining pixels are the white spots that satisfy the condition. From the equalized image data (YHist, CrHist, CbHist), the pixel points satisfying the corresponding position of the formula (3.14) are selected as the reference white pixels, and the average value (Rw, Gw, Bw) of the reference white pixels is calculated.
The color cast is judged on the image. If it is considered that there is no color shift, no processing is performed on the image; if it is judged that there is color shift, the corresponding scale factor is obtained according to the color cast level. The Von Kries transformation is also applied to correct the original data of the image, and the R, G, and B components of the image are updated. So far, the automatic white balance algorithm based on image color cast detection is completed.
$$ {\displaystyle \begin{array}{c}{R}^{\prime }=\left\{\begin{array}{c}R\ast {R}_{Gain}\to \ast {R}_{Gain}<255\\ {}255\to R\ast {R}_{Gain}>255\end{array}\right\}\\ {}{G}^{\prime }=\left\{\begin{array}{c}G\ast {R}_{Gain}\to \ast {G}_{Gain}<255\\ {}255\to G\ast {G}_{Gain}>255\end{array}\right\}\\ {}{B}^{\prime }=\left\{\begin{array}{c}B\ast {B}_{Gain}\to B\ast {B}_{Gain}<255\\ {}255\to B\ast {B}_{Gain}>255\end{array}\right\}\end{array}} $$
(11)
This study chooses the median filter method for image denoising. The previous median filter is a commonly used arrangement and summary method, which can effectively filter impulse noise and has high application value. However, in the process of system application, the details of the courseware image will be blurred, and the density of the pulse noise will increase. The filtering performance of this method shows a significant downward trend, which seriously hinders the application of multimedia systems in distance education. Therefore, we propose an improved median filtering method to further optimize the original algorithm to ensure the integrity of the course image details, and to solve the contradiction between the traditional algorithm cannot effectively deal with the filtering performance and image detail integrity. The improved median filtering algorithm can not only filter the noise factors in the courseware image, but also ensure the integrity of the courseware image details, which is the first choice for the system.
The past median filter operates on the pixel points of the image by the same operation method, which causes the value of the real signal point to change, and the image has a fuzzy problem, so it is not suitable for the system application of this paper. If the true pixel signal point and the signal point contaminated by noise are accurately distinguished, the misoperation of the true pixel signal point can be avoided, and the clarity of the courseware image can be improved. Using the improved switch median filtering method, the pixel of the courseware image can be accurately judged to avoid misoperation of the true pixel signal point. For a pixel of a suspected color image, there is a strong correlation between adjacent points, and the brightness value of a point in the image is close to the brightness value of the adjacent point. The pixel points of the isolated point of the pixel and the image portion of the edge portion are generally considered to be noise points. Therefore, in a courseware image, if there is a large difference between the value of a certain pixel point and its neighborhood value, the correlation between the pixel point and the neighborhood is low, and the point is considered to be a noise point, which needs to be performed filter processing. If the point value is close to the neighbor value, it is the true signal point.
The extreme median filtering algorithm evaluates noise, which has a strong processing power for large impulse noise. However, some thin lines in the color courseware image and the narrower edge details are also significantly different from the pixel values of the adjacent areas. At this time, the extreme median filtering algorithm will misjudge such pixel points into noise points, and accurate filtering of image noise points cannot be achieved.
Since the traditional median filtering algorithm has certain limitations, it needs to be optimized. Therefore, an improved median filtering algorithm based on median filtering theory is proposed. The improved method uses a method of summarizing between partitions to take a pixel point to be analyzed as a center point ((2N+ 1) × (2N + 1)) square range. The range is set as a window, and pixels in the window range can be arranged according to the brightness level, and the arranged pixel values are divided into 2N + 1 small ranges. The mean of 2N + 1 pixel values in the middle small range is used to describe the new pixel brightness at the center point. Unlike the conventional method, this method reduces and eliminates the high-frequency components of the Fourier region, and the high-frequency components are different from the pixel values of the luminance of the image edges. Therefore, the improved filtering algorithm can remove high frequency components in the image and ensure the flatness of the image. In the process of window image position transformation, the improved median filtering algorithm can maximize the smoothness of the image and improve the integrity of the image details. The specific process is as follows:
(1) In the courseware image, the (2N + 1) × (2N + 1) filter window is set to fuse the center of the filter window and a pixel in the image center. (2) The brightness values of different pixels in the filtering window are collected. (3) The ascending order is used to sort the luminance values and divide them into 2N + 1 number of segments, ensuring that each cell contains 2N + 1 number of pixel luminance values. (4) 2N + 1 number of pixel luminance values are collected between the central cells, and then, the average value of the pixel luminance values is obtained. (5) The obtained mean value is used to update the pixel value of the corresponding window center area. (6) Processes (3)–(5) are cycled until the corresponding analysis and operation are completed for all pixels. The output pixel of the improved median filtering algorithm has a strong correlation with the 2N + 1 number of pixel brightness value mean of the central segment of the adjacent range image. According to the correlation between the data points in the window, the damage data can be corrected, the noise points are filtered, the sharpness of the image is improved, and the integrity of the image details is ensured.