Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 9, No. 3, 2024 33 Visibility Detection Method Based on Automatic Image Recognition Xiuju Wang, Zhumu Fu, Kunning Zhai College of Information Engineering, Henan University of Science and Technology, Luoyang, Henan, China Abstract: Visibility detection has great research and practical application value in the fields of weather forecasting and autonomous driving. At the same time, the existing visibility detection methods have some problems, such as the high price of hardware equipment, the need to set specific markers, and the large amount of calculation. In this paper, a visibility detection algorithm based on automatic image recognition is proposed, which calculates the light intensity of the target area of the image through a series of image processing, calculates the corresponding transmittance through the dark channel prior algorithm, and then inverts the atmospheric visibility according to the Koschmieder atmospheric visibility measurement principle. The corresponding fog concentration coefficient under different visibility conditions was measured by experiments, and the visibility value calculated based on the image and the visibility value of the CJY-1G forward visibility scattering instrument were compared, and the error percentage before the two was calculated, so as to verify that the visibility value detected by the method used in this chapter can fully meet the specified error range and meet the application requirements of visibility observation. Keywords: Dark channel prior algorithm, Image recognition, visibility. 1. Introduction Visibility detection plays an important role in transportation, navigation, and operational safety during transportation. At present, there are three main methods for visibility detection: instrument detection method、visual inspection metho and camera method. Scholars at home and abroad have proposed various methods for detecting visibility through photography. Reference [1] proposes the idea of using visual features of images to measure visibility, which involves manually taking photos, developing them, calculating the contrast between the target object and the background, and calculating the visibility value. Reference [2] proposed visibility detection based on whether the camera can observe targets at different distances on highways. Reference [3] proposed the average gradient algorithm and transmittance ratio method. Reference [4] judges foggy weather by dynamically calibrating the parameters inside and outside the camera and analyzing the average pixel fitting curve of the region of interest in the activity map. Reference [5] detects atmospheric visibility based on the average grayscale value and exposure time of images by setting strict parameters for monitoring cameras. Reference [6] modified the weights of the MSR algebraic model based on image enhancement methods. In summary, visibility detection technology has become quite mature and has made significant progress and breakthroughs. However, existing algorithms still have many shortcomings, such as high complexity, inconvenient detection, and inability to be widely promoted and applied. This article can use existing monitoring equipment to obtain the target area light intensity of the image through a series of image processing. Through a dark channel prior algorithm, the corresponding transmittance can be calculated. Then, based on the principle of calculating atmospheric visibility using the Cauchy Mead method, atmospheric visibility can be inverted. 2. Theoretical Basis The theoretical basis for visibility detection is Koschmieder's law [7], which establishes the relationship between atmospheric extinction coefficient and visibility, expressed as  0 1d dL L e A e     (2-1)         1I x J x t x A t x   (2-2) L and 0L respectively are the observed brightness value and intrinsic brightness value of the object,  refers to atmospheric extinction coefficient, d refers to the distance at which parallel light attenuates through the atmosphere to 0.05 of the original luminous flux, A refers to atmospheric transmittance intensity,  I x refers to original image,  J x refers to clear image without fog,  t x refers to atmospheric transmissivity. The relationship between the distance between a certain point in the image and the camera d, the atmospheric extinction coefficient of this scene  and atmospheric transmissivity  t x is           x d xt x e J x A x       (2-3)  x refers to albedo. Substituting equation (2-3) into equation (2-2) yields 34                    1 , 0,1 x d x x d x x d x I x A x e A e e            (2-4) Based on the relevant models mentioned above, the International Commission on Illumination (CIE) has defined the formula for calculating visibility as  1 3 ln 0.05metV      (2-5) metV refers to visibility. 3. A Method for Measuring Atmospheric Visibility Based on Automatic Image Recognition Firstly, we transfer the captured image as the original target image to the PC, and first perform regular image segmentation on the image, cutting out the complex and useless parts at the bottom of the image, eliminating interference, and reducing errors; Reuse the OTSU adaptive threshold method to perform global automatic threshold segmentation on the image, distinguishing the target from the background, and then use the continuous dilation of mathematical morphology to segment the connected domain of the image; Then, search for "pseudo" centroids in the multi connected domain; Finally, the transmittance is calculated using the dark channel prior algorithm, and the area where the target area with the highest intensity is located in the dark channel is selected as the final target area for visibility calculation. Combined with the Koschmieder law of atmospheric visibility, the experimental atmospheric visibility value is calculated. Figure 1. Diagram of visibility measurement system for automatic image recognition 3.1. Rule based image segmentation In practical work, we use visual sensors to capture target images with complex content and a lot of information, including most of the useless information. Usually, it is necessary to cut the captured images according to work requirements [8]. Therefore, we will cut the captured images to remove irrelevant information and only leave the target area. The original image is shown in Figure 2 (a), a cut image was obtained as shown in Figure 2 (b). (a) Original image (b) Crop Image Figure 2. Image Cropping Results 3.2. Image adaptive threshold segmentation based on OTSU The OTSU adaptive threshold segmentation method, also known as the Otsu threshold segmentation method, was proposed by Japanese expert Nobuyuki Otsu in 1979. It is an image grayscale adaptive threshold segmentation algorithm that divides the image into two parts: background and foreground, based on the distribution of grayscale values on the image. The foreground is the part that we need to segment according to the threshold. The boundary value between background and foreground is the threshold we require. Traverse different thresholds and calculate the intra class variance between the background and foreground corresponding to different thresholds. When the intra class variance reaches its maximum value, the corresponding 35 threshold is the threshold obtained by the Otsu method also known as the maximum inter class variance method [9]. This method is simple to calculate, has strong stability, and is not easily affected by the brightness and contrast of the image itself. Therefore, it is widely used in digital image processing. For images captured in different weather conditions and scenes, artificially set thresholds are not entirely applicable. Therefore, according to the requirements of this article, we adopt the method of automatic threshold selection for processing, and OTSU is an automatic threshold calculation method that can automatically obtain different thresholds suitable for different grayscale images, effectively segmenting targets and backgrounds. The threshold T obtained from the OSTU processing of the original image taken on the morning of November 16, 2023 is converted to [0-255], resulting in a threshold T of 144; The rendering is as follows: (a) Original grayscale image (b) OTSU global threshold segmentation Figure 3. Result Graph of OTSU Threshold Segmentation Methods 3.3. Continuous expansion of images Expansion operations are commonly used to fill target areas, connect disconnected parts, and reconstruct images. Simply put, it means defining a structural element, usually a small image or convolution kernel, which is used to slide over the input image. Then compare the structural elements with the input image. If the shape of the structural elements matches the objects in the image, the pixel values at the corresponding positions in the output image will be set as foreground values, otherwise they will remain unchanged. The specific operation is to scan each pixel in the image with a structural element, and perform an AND operation with each pixel in the structural element and the pixel it covers. If both are 0, the pixel is 0, otherwise it is 1. As shown in the following figure: (a) target image (b) structure element (c) expansion result Figure 4. Expansion Process Diagram The basic forms of structural elements generally include rectangles, crosses, or ellipses (circles). However, there may be slight differences when processing images with different structural elements. Therefore, based on the obvious sharp protrusions and irregular shaped objects in the target images captured in the experiment, this article chooses diamond shaped cross structural elements to maintain the original contour shape of the object to the greatest extent possibl. The original image taken on the morning of November 16, 2023, after OTSU threshold segmentation, was inflated using the diamond shaped cross structure elements in the above equation. In order to better eliminate useless areas, the target image is subjected to multiple continuous dilation operations, that is, the image taken on the morning of November 16, 2023 is subjected to multiple continuous dilation operations, as shown in Figure 5. (a) Image after one expansion (b) Image after secondary expansion (c) Image after three expansions (d) Image after four expansions Figure 5. Image Continuous Expansion Effect Map 36 From Figure 5, it can be seen that compared with the results of one expansion, the small and complicated points in the middle have been eliminated. Therefore, the results of four expansions were selected for processing. 3.4. Target area selection After a series of grayscale transformations, threshold segmentation, and continuous dilation expansion, the original image captured is segmented into clearly independent multiple regions. By labeling the white target object in the binary image, each independent connected domain is formed into a recognition block, and then the geometric parameters of these blocks, such as contour, centroid, and invariant moments, are obtained. Connected region generally refers to the image area composed of foreground pixels with the same pixel value and adjacent positions in the image. When conducting connected region analysis, we use 8- neighborhood segmentation to provide a basis for the subsequent search for "pseudo" centroids. Due to the fact that some moments in the image region are invariant to geometric transformations such as rotation, translation, and scaling, the expression method of moments is widely used in object classification and recognition. The image after continuous expansion has obvious regional differentiation, and it is necessary to select the target area of the image. First, we need to find a certain position feature point within the obvious region, and then label the region. Using the principle of finding centroids, we first find the "pseudo" centroids of the image's multi connected regions. To obtain the centroid of the image after expansion processing, it is necessary to first perform a reverse coloring operation on the image, as shown in Figures 6. (a) Expansion effect diagram (b) Inverse coloring graph Figure 6. Image Anti-coloring Effect Map For an image (single channel image), it can be seen as a flat object, and its first and zero moments can be used to calculate the center of gravity of a certain shape. We use the method of finding the centroid to process the multi connected domains of the dilated anti colored image, obtain the "pseudo" centroids of each connected domain, and use plot to locate the image position, marking the "pseudo" centroids with an "*" sign. As shown in Figure 7, the "pseudo" centroid marking effect is obtained from the original image taken on the morning of November 16, 2023, after four rounds of dilation and anti coloring. Figure 7. Pseudo Centroid Marking Effect Map After marking the "pseudo" centroid, we have found the center of the connected area in the image. Next, we will mark the target area and select the "pseudo" centroid as the center of the target area. Mark the original image taken on the morning of July 24, 2023, as shown in Figure 8. Figure 8. Target Area Marking of Original Image The number and position of "pseudo" centroids in different processed images are different, and the marking position of the target area is also different. Therefore, we need to use the transmittance calculation method in the dark channel prior algorithm to select the coordinate area with the highest light intensity, i.e. the lowest transmittance, in the dark channel 37 map as the final target area, and then obtain the atmospheric extinction coefficient for the final visibility calculation. 4. Experimental Results and Analysis After a series of processing, the image finally obtains the target area and the corresponding intensity value and atmospheric light value of the target area. However, different fog concentration coefficients have a significant impact on the calculation of transmittance. The transmittance values calculated for images with different degrees of atomization are different. Therefore, if a fixed value of  is selected to estimate the corresponding transmittance, the degree of atomization caused by different weather changes in the image is not considered, There will be significant errors. Therefore, based on a large number of experimental comparisons, we have obtained the relationship between fog concentration coefficient and visibility as shown in Table 1. Table 1. Relationship between fog concentration coefficient selection and visibility V Fog concentration coefficient  Visibility V/m 0.90-0.95 1500V  0.80-0.85 1500 2000V  0.70-0.75 2000 2500V  0.60-0.65 2500 3000V  0.50-0.55 3000 4000V  0.40-0.45 4000 6000V  0.30-0.35 6000 10000V  0.20-0.25 10000 20000V  0.10-0.15 20000 V According to Tables 1, the selection of fog concentration coefficient has a significant impact on the visibility calculation results. The selection of different visibility ranges and defogging coefficients was corresponding through experiments. Appropriate fog concentration coefficients must be required in different visibility ranges to ensure the accuracy of the calculation results. Based on the above calculation method, we conducted visibility calculations on the selected 31 day images and compared the results with the true values of the CJY-1G forward visibility scatterometer taken on the fifth floor of the building of Kaimai (Luoyang) Measurement and Control Co., Ltd. at 105 Jiefang Road, Xigong District, Luoyang City. The comparison between the calculated visibility and the forward scatter meter visibility is shown in Figure 9. Figure 9. Visibility Comparison Chart for 31 Days We compared the visibility values measured by the CJY- 1G forward visibility scatterometer with the visibility measurement values based on image automatic recognition. From Figure 10, it can be seen that the visibility curve based on image calculation is basically consistent with the visibility curve of the CJY-1G forward visibility scatterometer, and the data is roughly similar. Figure 10 shows the variation of error values between the selected 31 days image visibility measurement values and the CJY-1G forward visibility scatterometer measurement values. 0 5000 10000 15000 20000 25000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 V is ib il it y di st an ce /m Date Comparison chart of visibility CJY-1G forward visibility scatterometer Visual visibility based on image measurement 38 Figure 10. Percentage error change This article is based on the estimation of visibility using the principle of dark channel priors in images. The CJY-1G forward scattering instrument data is used as the true value, with a minimum measurement error of 0.16% and a maximum relative error of 18.02%. The accuracy requirement of the forward scattering instrument CJY-1G is that the allowable error range is ±10% when visibility is≤1500m, and ±20% when visibility is≥1500m. According to the MOR regulations of the World Meteorological Organization, the relative error of the visibility instrument within the entire detection range is ≤±20% to meet the standard and can be put into use. The visibility values detected by the method used in this chapter fully meet the specified error range and meet the application requirements of visibility observation. 5. Conclusion This article calculates the light intensity of the target area of the image through a series of image processing, calculates the corresponding transmittance through a dark channel prior algorithm, and then calculates the atmospheric visibility based on the principle of measuring atmospheric visibility using the Cauchy Mead method. The corresponding fog concentration coefficients were measured through experiments under different visibility levels, and the visibility values based on image calculation were compared with those of the CJY-1G forward visibility scatterometer. The percentage of error between the two was calculated to verify that the visibility values detected by the method in this chapter can fully meet the specified error range and meet the application requirements of visibility observation. References [1] Steffens C. Measurement of visibility by photographic photometry [J]. Industrial Engineering Chemistry, 1949, 41(11): 2396-2399. [2] Kwon T M.Atmospheric visibility measurements using video cam eras: relative visibility[EB/OL].[2012-07-20]. [3] Wenshu Xiang. Research on visibility estimation based on traffic videos [D]. Shanghai: Shanghai Jiao Tong University, 2014. [4] Guo F, Peng H, Tang J, et al. Visibility detection approach to road scene foggy images[J]. KS Ⅱ Transactions on Internet & Information Systems, 2016,10 (9): 4419-4441. [5] Jing Han, Pingping Yu, Zhenzhou Wang, et al. Road visibility detection algorithm based on camera response curve fitting [J]. Journal of Yanshan University 2018, 42 (3): 272-277. [6] Wu H T, Lan J H.A novel fog-degraded image restoration model of golden scale extraction in color space[J]. Arabian Journal for Science and Engineering, 2018, 43(12): 6801- 6821. [7] Qian Xu, Xucheng Yin, Yan Li, et al. A visibility measurement method based on image understanding [J]. Pattern Recognition and Artificial Intelligence, 2013, 26 (06): 543-551. [8] Anonymous.Resize in Image Processing [EB/OL] https://www.cnblogs.com/ Qiqibaby/p/8626516. html.2015, 03. [9] Si Chen. Binarization of license plate images based on Otsu algorithm and its Matlab implementation [J] Journal of Changchun Normal University, 2012, 31 (03):33-35. -0.1 -0.05 0 0.05 0.1 0.15 0.2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Percentage error variation chart