# Advancing Nighttime Object Detection through Image Enhancement and Domain Adaptation
## 3 Methodology
### LightImg  
Because the purpose of this study is cross-domain recognition, we propose LightImg, as shown in Figure 3, a module that can directly convert existing nighttime datasets into daytime datasets, enabling the use of existing nighttime datasets to complete tasks. This is a lightweight module that does not require excessive computational resources [14; 19]. The enhancement by LightImg aims to transform the features of nighttime images into those of daytime images. Daytime images generally have higher brightness, clearer light sources, and more detailed backgrounds compared to nighttime images. The dynamic range (HDR) of daytime images may also be higher. Additionally, outside city centers, the influence of artificial light sources is also reduced. Let \(Y(x,\ y)\) be the original nighttime image, where \(L(x,\ y)\) and \(R(x,\ y)\) represent the luminance and reflectance components, respectively. The relationship is given by  
\[Y(x,\ y)=L(x,\ y)R(x,\ y) \tag{12}\]  
We know that the relationship between the input nighttime image \(y\) and the output clear image \(R\) is given by \(y=Z\bigotimes R\), where \(Z\) represents the illumination component. Generally, illumination is considered the core component that needs to be optimized for low-light image enhancement. According to the Retinex theory [21], the input image consists of two parts: the luminance component \(L\) and the reflectance component \(R\). The enhanced results at different scales are linearly combined, taking into account both local and overall illumination components. This multi-scale algorithm ultimately produces images with good dynamic range compression, color stability, and color restoration. First,we divide the nighttime image \(\mathrm{Y(x,y)}\) into several scale levels based on grayscale values and separate the three color components. Then, different Gaussian surround functions \(\mathrm{G_{k}(x,y)}\) are constructed according to the ratios of 15:80:250. These Gaussian surround functions are used to perform convolution filtering on the R, G, and B color channels, and the illumination components are obtained by weighted averaging:  
\[L(x,\ y)=\sum_{k=1}^{N}\omega_{k}(I_{i}(x,\ y)\ *\ G_{k}(x,\ y)) \tag{13}\]  
Here, \(\sum_{k=1}^{N}\omega=1,\mathrm{I_{i}(x,y)}\) is the pixel value of the original image, with \(N=3\) in the RGB color space, and iii represents the three color channels. Then, we take the logarithm and subtract the illumination component from the original image:  
\[\log\mathrm{R_{i}}=\sum_{k=1}^{N}\omega_{k}(\log(\mathrm{I_{i}(x,y)}))-\mathrm{ L(x,y)} \tag{14}\]  
The previous steps may result in local detail color distortion and fail to reveal the true colors of objects. Therefore, we add a color restoration step to address this issue:  
\[C_{i}(x,\ y)=\frac{I_{i}(x,\ y)}{\sum_{j=1}^{N}I_{j}(x,\ y)} \tag{15}\]  
j also represents the three color channels. By combining Equations (14) and (15), we obtain the calculation formula for our LightImg:  
\[\log\mathrm{R_{LightImg}}=C_{i}(x,\ y)\cdot\log\mathrm{R_{i}(x,y)} \tag{16}\]  
Here, \(\alpha\) is used to adjust the nonlinear transformation, and \(\beta\) is the gain constant. Algorithm 1 demonstrates the process of a single enhancement using LightImg. The pseudocode for Equations (1)-(16) is presented in Algorithm 2.