Image defogging method in complex environment
By comprehensively utilizing saturation, brightness, and contrast to determine dense fog areas, constructing a fog mask, and training it in conjunction with a specific network, the problem of difficult fog boundary localization in existing technologies is solved, thus improving the image dehazing effect.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-08
- Publication Date
- 2026-03-31
AI Technical Summary
Current image dehazing methods struggle to locate dense fog boundaries when dealing with non-uniform haze images, which are more prevalent in the real world, resulting in unsatisfactory image fidelity and restoration after dehazing.
By comprehensively determining the fog areas by obtaining the saturation, brightness, and contrast values of the original image, a fog mask is constructed, and the edge and texture structure is enhanced using the fog mask. The D-Transformer and R-Transformer networks are combined for iterative training, and a comprehensive loss function is constructed to optimize the defogging model.
It achieves accurate identification and localization of dense fog regions in non-uniform fog images, improves the preservation of details, structural integrity and visual realism of dehazed images, and ensures the superiority of dehazing effect.
Smart Images

Figure CN121458593B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image dehazing method for complex environments. Background Technology
[0002] In severe weather conditions such as fog and haze, suspended particles in the atmosphere absorb and scatter light, resulting in degradation phenomena such as decreased contrast, color distortion, and blurred details in the acquired images. With the introduction of deep learning technology into the field of image dehazing, the dehazing effect on non-uniform fog images has been effectively improved.
[0003] Current image dehazing methods estimate fog concentration information in the image through a fog concentration information estimation module to obtain dense fog areas. Fog concentration information is then introduced into the dehazing network to achieve adaptive dehazing, thereby removing dense fog areas from the image.
[0004] However, this method largely depends on the accuracy of fog concentration estimation. When dealing with non-uniform fog images that are more common in the real world, it still faces problems such as difficulty in locating dense fog boundaries and unsatisfactory image fidelity and restoration after defogging. Summary of the Invention
[0005] The purpose of this invention is to provide an image dehazing method in complex environments, so as to solve the problems mentioned in the background art, such as the difficulty in locating the boundary of dense fog and the unsatisfactory image fidelity and restoration after dehazing.
[0006] To achieve the above objectives, the present invention provides the following technical solution: an image dehazing method under complex environments, comprising the following steps: acquiring an original image containing non-uniform fog, and preprocessing the original image; comprehensively determining the dense fog regions in the image based on the saturation, brightness, and contrast values of the original image, constructing a fog mask based on the dense fog regions, and using the fog mask to enhance the fog region edges and texture structure of the dense fog regions in the original image; constructing a fog region dataset using the feature-enhanced original image and the corresponding fog mask, inputting the fog region dataset into a dehazing network model for iterative training, using the trained dehazing network model to perform image dehazing and restoration, and generating a clear dehazed image; constructing a comprehensive loss function containing a fog weighting mechanism based on the pixel differences, structural differences, perceptual differences, and texture differences between the clear dehazed image and the real fog-free image, and optimizing the dehazing network model until it meets the preset model performance evaluation criteria.
[0007] Optionally, the step of comprehensively determining the fog region in the image based on the saturation value, brightness value, and contrast value of the original image specifically includes: performing HSV space conversion on the original image; obtaining the saturation value, brightness value, and contrast value of the original image, and setting a saturation threshold, a brightness threshold, and a contrast threshold; determining the region where the saturation value is lower than the saturation threshold, the brightness value is higher than the brightness threshold, and the contrast value is lower than the contrast threshold as the fog region.
[0008] Optionally, the step of constructing a fog mask based on the dense fog region specifically includes: using an edge detection algorithm to extract edges from the original image to obtain an edge texture map, and performing an intersection operation between the edge texture map and the dense fog region to obtain the fog mask.
[0009] Optionally, the step of enhancing the fog area edges and texture structure of the fog region in the original image using the fog mask specifically includes: performing pixel mapping between the fog mask and the original image to locate the fog region in the original image; performing linear multiplication in the saturation channel of the HSV space to enhance the vividness of the fog region, and then performing local histogram equalization on the saturation channel of the same HSV space to enhance the contrast of the fog region, thereby obtaining a visually enhanced image; using the original image as a guide image, performing guided filtering on the visually enhanced image to preserve edges and textures within the enhanced region, thereby obtaining a structurally enhanced image; and fusing the structurally enhanced image with the original image to obtain the target enhanced image.
[0010] Optionally, the construction steps of the dehazing network model specifically include: constructing a D-Transformer network based on deformable convolution DCNv4; simultaneously inputting the fog mask and the original image after feature enhancement into the D-Transformer network to obtain image enhancement features; generating a corresponding attention map from the fog mask through the attention submodule in the D-Transformer network; performing a channel multiplication operation between the attention map and the image enhancement features to enable the D-Transformer network to learn fog features, thereby outputting a preliminary dehazed image; constructing an R-Transformer network based on the Retinex algorithm; inputting the preliminary dehazed image into the R-Transformer network to obtain image weighted features; performing another channel multiplication operation between the image weighted features and the attention map to enable the R-Transformer network to prioritize the recovery of fog color and details, ultimately outputting a clear dehazed image.
[0011] Optionally, the step of constructing a comprehensive loss function including a fog weighting mechanism based on the pixel differences, structural differences, perceptual differences, and texture differences between the clear dehazed image and the real fog-free image specifically includes: obtaining the pixel differences, structural differences, perceptual differences, and texture differences between the clear dehazed image and the real fog-free image; introducing the fog mask as a weighting factor into the calculation of at least one loss, so that the model training assigns higher optimization weights to foggy areas; and constructing a comprehensive loss function by weighting and summing the pixel differences, structural differences, perceptual differences, and texture differences based on preset difference weights.
[0012] Optionally, the formula for calculating the comprehensive loss function is: L_total = α×L1'+β×L_S' +γ×L_p+δ×L_G; where: L_total is the total loss function, α, β, γ, and δ are hyperparameters used to balance the contributions of each loss, L1' is pixel difference, L_S' is structural difference, L_p is perceptual difference, and L_G is texture difference; wherein, both the pixel difference L1' and the structural difference L_S' introduce a fog weighting mechanism, and the loss function of the fog weighting mechanism is: L_weighted=L_original⊙(1+λM); where: L_weighted is the fog weighting loss function, L_original is the original pixel-level loss map, λ is the weighting factor, ⊙ is element-wise multiplication, and M is the binary fog mask.
[0013] On the other hand, the present invention also provides an image dehazing system for complex environments, comprising: an acquisition module for acquiring an original image containing non-uniform fog and preprocessing the original image; a fog enhancement module for comprehensively determining dense fog regions in the image based on the saturation, brightness, and contrast values of the original image, constructing a fog mask based on the dense fog regions, and using the fog mask to enhance the fog edges and texture structure of the dense fog regions in the original image; a dehazing module for constructing a fog dataset using the feature-enhanced original image and the corresponding fog mask, inputting the fog dataset into a dehazing network model for iterative training, using the trained dehazing network model to perform image dehazing and restoration, and generating a clear dehazed image; and a model optimization module for constructing a comprehensive loss function containing a fog weighting mechanism based on the pixel differences, structural differences, perceptual differences, and texture differences between the clear dehazed image and the real fog-free image, optimizing the dehazing network model until it meets a preset model performance evaluation standard.
[0014] On the other hand, the present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described image dehazing method under complex environments.
[0015] On the other hand, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the above-described image dehazing method under complex environments.
[0016] Compared with the prior art, the beneficial effects of the present invention are:
[0017] This application addresses the processing of raw images containing non-uniform fog. By fusing multi-dimensional visual features such as saturation, brightness, and contrast, it achieves accurate and robust identification and localization of dense fog regions in non-uniform fog images, overcoming the drawbacks of single features being easily interfered with. The generated accurate fog mask is used to specifically enhance the raw image, strengthening the edge texture features of dense fog regions while effectively preserving the overall structural information of the image. This constructs a fog region dataset, allowing the training process of the dehazing network model to fully learn the complex mapping relationship between dense fog regions and clear images, ultimately resulting in an optimized model for image dehazing and restoration in complex environments. By constructing a comprehensive loss function that integrates multi-dimensional differences such as pixel, structure, perception, and texture, and introducing a fog region weighting mechanism, comprehensive and targeted guidance signals are provided for model optimization. This allows the model training to not only focus on the global image restoration accuracy but also to emphasize the optimization of dense fog regions, thereby significantly improving the overall performance of the dehazed image output in terms of detail preservation, structural integrity, and visual realism, ensuring superior dehazing results. Attached Figure Description
[0018] Figure 1 This is a schematic diagram of the method steps of the present invention.
[0019] Figure 2 This is a block diagram illustrating the principle of the method of the present invention.
[0020] Figure 3 This is a schematic diagram of the system structure of the present invention.
[0021] In the diagram: 10 - Acquisition module, 20 - Fog enhancement module, 30 - Defogging module, 40 - Model optimization module. Detailed Implementation
[0022] The present invention will now be clearly and completely described in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.
[0023] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be used interchangeably where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0024] Those skilled in the art will understand that, unless explicitly stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in the specification of this application means the presence of features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.
[0025] It will be understood by those skilled in the art that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0026] It should be understood that the sequence number and size of each step in this embodiment do not imply the order of execution. The execution order of each process is determined by its function and internal logic, and should not constitute any limitation on the implementation process of this application embodiment.
[0027] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0028] Please refer to Figures 1-2This invention discloses an image dehazing method for complex environments, comprising the following steps: acquiring an original image containing non-uniform fog; preprocessing the original image; comprehensively determining dense fog regions in the image based on the saturation, brightness, and contrast values of the original image; constructing a fog mask based on the dense fog regions; enhancing the fog region edges and texture structure of the dense fog regions in the original image using the fog mask; constructing a fog region dataset using the feature-enhanced original image and the corresponding fog mask; inputting the fog region dataset into a dehazing network model for iterative training; using the trained dehazing network model to perform image dehazing and restoration, generating a clear dehazed image; constructing a comprehensive loss function including a fog weighting mechanism based on the pixel differences, structural differences, perceptual differences, and texture differences between the clear dehazed image and the real fog-free image; optimizing the dehazing network model until it meets a preset model performance evaluation standard.
[0029] Specifically, original images containing non-uniform fog under different environments and their corresponding real fog-free images are acquired, and the original images are then cropped and normalized sequentially.
[0030] The original image is spatially transformed to obtain its saturation, brightness, and contrast values. Saturation, brightness, and contrast thresholds are set to determine the fog regions in the original image. An edge detection algorithm is used to extract the edges of the original image to obtain an edge texture map. The intersection of the edge texture map and the fog regions is then performed to obtain the fog mask.
[0031] In this embodiment of the invention, the cropping process includes: cropping the original image to obtain a cropped image, calculating the pixel mean and pixel standard deviation, and then normalizing the cropped image. The normalization process can be expressed as:
[0032] ;
[0033] In the formula: Z represents the normalized original image, and R represents the cropped image. x i and y i They represent the first i The x and y coordinates of each pixel. μ r and σ r These represent the pixel mean and pixel standard deviation of the cropped image, respectively.
[0034] This application addresses the processing of raw images containing non-uniform fog. By fusing multi-dimensional visual features such as saturation, brightness, and contrast, it achieves accurate and robust identification and localization of dense fog regions in non-uniform fog images, overcoming the drawbacks of single features being easily interfered with. The generated accurate fog mask is used to specifically enhance the raw image, strengthening the edge texture features of dense fog regions while effectively preserving the overall structural information of the image. This constructs a fog region dataset, allowing the training process of the dehazing network model to fully learn the complex mapping relationship between dense fog regions and clear images, ultimately resulting in an optimized model for image dehazing and restoration in complex environments. By constructing a comprehensive loss function that integrates multi-dimensional differences such as pixel, structure, perception, and texture, and introducing a fog region weighting mechanism, comprehensive and targeted guidance signals are provided for model optimization. This allows the model training to not only focus on the global image restoration accuracy but also to emphasize the optimization of dense fog regions, thereby significantly improving the overall performance of the dehazed image output in terms of detail preservation, structural integrity, and visual realism, ensuring superior dehazing results.
[0035] In some embodiments, the step of comprehensively determining the fog region in the image based on the saturation value, brightness value, and contrast value of the original image specifically includes: performing HSV space conversion on the original image; obtaining the saturation value, brightness value, and contrast value of the original image, and setting a saturation threshold, a brightness threshold, and a contrast threshold; determining the region where the saturation value is lower than the saturation threshold, the brightness value is higher than the brightness threshold, and the contrast value is lower than the contrast threshold as the fog region.
[0036] Specifically, the normalized original image is converted to HSV space and grayscale space respectively. Using the saturation and luminance channels of the HSV space and the grayscale space, the saturation value, luminance value and contrast value of the original image are obtained respectively. 65% of the saturation value, luminance value and contrast value of each original image are used as the saturation threshold, luminance threshold and contrast threshold of the image respectively. The area where the saturation value is lower than the saturation threshold, the luminance value is higher than the luminance threshold and the contrast value is lower than the contrast threshold is determined as the fog area.
[0037] This application comprehensively identifies foggy areas by using three visual features—saturation, brightness, and contrast—based on the HSV color space, thereby improving the accuracy and interpretability of the determination. This multi-feature fusion determination strategy can effectively distinguish foggy areas from other interference areas in the image with similar single features, significantly reducing the false positive rate of fog area detection.
[0038] In some embodiments, the step of constructing a fog mask based on the dense fog region specifically includes: using an edge detection algorithm to extract edges from the original image to obtain an edge texture map, and performing an intersection operation on the edge texture map and the dense fog region to obtain the fog mask.
[0039] Specifically, the Canny operator is used to perform edge recognition and extraction on the original image to obtain the edge texture map. The intersection operation is then performed on the edge texture map and the fog region to obtain the fog mask.
[0040] This application introduces edge detection and performs intersection calculations with the initially identified dense fog region. This ensures that the final fog mask accurately matches the true boundary of the dense fog region, while effectively eliminating false detections within flat fog areas that are not edges. This guarantees the boundary accuracy and internal consistency of the fog mask, providing high-precision spatial guidance information for subsequent localized feature enhancement and model optimization.
[0041] In some embodiments, the step of enhancing the fog area edges and texture structure of the fog region in the original image using the fog mask specifically includes: performing pixel mapping between the fog mask and the original image to locate the fog region in the original image; performing linear multiplication in the saturation channel of the HSV space to enhance the vividness of the fog region, and then performing local histogram equalization on the saturation channel of the same HSV space to enhance the contrast of the fog region, thereby obtaining a visually enhanced image; using the original image as a guide image, performing guided filtering on the visually enhanced image to preserve edges and textures within the enhanced region, thereby obtaining a structurally enhanced image; and fusing the structurally enhanced image with the original image to obtain a target enhanced image.
[0042] Specifically, the fog mask and the original image are pixel-mapped to further accurately locate the dense fog region. The saturation and contrast values of the dense fog region are multiplied by saturation and contrast factors, both greater than 1, such as performing linear multiplication in the saturation channel of the HSV color space to enhance the vividness of the fog region. The saturation factor is set to 1.1 to enhance the vividness of the fog region. Then, local histogram equalization is performed on the saturation channel of the same HSV color space, and the contrast factor is set to 1.05 to enhance the contrast of the fog region, thereby highlighting the features of the dense fog region and obtaining a visually enhanced image.
[0043] The pixel mean, pixel variance, and pixel covariance of the original image and the preliminary enhanced image are obtained. A local linear model between the pixels of the original image and the preliminary enhanced image is constructed. The preliminary enhanced image is fitted and optimized based on the local linear model to obtain the original image after feature enhancement.
[0044] Specifically, for any position in the original image k neighborhood window w k Any pixel within the range can be represented in the original image after feature enhancement as:
[0045] ;
[0046] In the formula, O This represents the original image after feature enhancement. A k Represents linear coefficients. B k This represents the bias term. The linear coefficients... A k and the bias term B k The expression is:
[0047]
[0048] In the formula: U This refers to the initial enhanced image. The original image and the preliminary enhanced image are represented in the neighborhood window. The pixel covariance within, The original image is represented in the neighborhood window. The pixel variance within, ε Represents the regularity coefficient. Indicated in the neighborhood window The average value of the pixels within.
[0049] By using fog masking, feature enhancement is performed on the dense fog region in the original image containing non-uniform fog. This preserves the fog edge and texture structure features of the dense fog region in the original image. At the same time, using the original image as a guide image, guided filtering can maintain the overall structural information of the image while avoiding phenomena such as over-enhancement, noise amplification, and artifacts that may exist after feature enhancement.
[0050] This application sequentially performs pixel mapping, saturation and contrast enhancement, guided filtering, and image fusion to achieve targeted enhancement of the visual characteristics of foggy areas. While improving the vividness and contrast of foggy areas, guided filtering effectively preserves the edge structure and texture details of the original image, avoiding noise amplification or artifacts that may be introduced during the enhancement process. The final output is a feature-enhanced image with richer details, which is more conducive to subsequent dehazing network processing.
[0051] In some embodiments, the construction steps of the dehazing network model specifically include: constructing a D-Transformer network based on deformable convolution DCNv4; simultaneously inputting the fog mask and the original image after feature enhancement into the D-Transformer network to obtain image enhancement features; generating a corresponding attention map from the fog mask through the attention submodule in the D-Transformer network; performing a channel multiplication operation between the attention map and the image enhancement features to enable the D-Transformer network to learn fog features, thereby outputting a preliminary dehazing image; constructing an R-Transformer network based on the Retinex algorithm; inputting the preliminary dehazing image into the R-Transformer network to obtain image weighted features; performing another channel multiplication operation between the image weighted features and the attention map to enable the R-Transformer network to prioritize the recovery of fog color and details, ultimately outputting a clear dehazing image.
[0052] Specifically, a D-Transformer network is constructed using the deformable convolution DCNv4. The fog mask and the original image after feature enhancement are simultaneously input into the D-Transformer network to obtain image enhancement features. The attention submodule generates a corresponding attention map from the fog mask. The attention map and the image enhancement features are multiplied by a channel to obtain image dehazing features. The image dehazing features are then processed by the D-Transformer network to output the preliminary dehazing image.
[0053] An R-Transformer network is constructed based on the Retinex image restoration algorithm. The initial dehazed image is input into the R-Transformer network to obtain image weighted features. The image weighted features and the attention map are multiplied by the channel to obtain image restoration features. The image restoration features are processed by the R-Transformer network to output the clear dehazed image.
[0054] This application constructs a dual-network collaborative architecture of D-Transformer and R-Transformer, sharing an attention map generated from the fog mask, thus achieving cascaded optimization of the dehazing process. This allows the dehazing network to focus on learning fog features in the initial dehazing stage, and to reuse the same attention map in the image restoration stage to prioritize the restoration of color and details in the fog area. This ensures the dehazing model's ability to handle the core challenging region of dense fog and its restoration accuracy, achieving targeted and precise dehazing.
[0055] In some embodiments, the step of constructing a comprehensive loss function including a fog weighting mechanism based on the pixel differences, structural differences, perceptual differences, and texture differences between the clear dehazed image and the real fog-free image specifically includes: obtaining the pixel differences, structural differences, perceptual differences, and texture differences between the clear dehazed image and the real fog-free image; introducing a fog mask as a weighting factor into the calculation of at least one loss, so that the model training assigns higher optimization weights to foggy regions; and constructing a comprehensive loss function by weighting and summing the pixel differences, structural differences, perceptual differences, and texture differences based on preset difference weights.
[0056] Specifically, the foggy dataset is randomly divided into a training set and a test set in a 9:1 ratio. The dehazing network model is iteratively trained using the training set. A comprehensive loss function with a fog weighting mechanism is constructed based on the pixel differences, structural differences, perceptual differences, and texture differences between the clear dehazed image and the real fog-free image. This function is used to optimize the dehazing network model. A maximum number of iterations is set, and an early stopping mechanism is introduced to obtain the trained dehazing network model. The test set is input into the trained dehazing network model, and the peak noise ratio and structural similarity between the clear dehazed image and the fog-free image are calculated. Peak noise thresholds and structural similarity thresholds are set to obtain the trained dehazing network model.
[0057] The Adam optimizer was selected as the optimization algorithm during training. The learning rate of the Adam optimizer was set to 1e-4, the decay rate for first-order moment estimation was set to 0.9, the decay rate for second-order moment estimation was set to 0.999, and the numerical stability parameter was set to 1e-7. The parameters of the Adam optimizer were dynamically adjusted after each round of training iterations.
[0058] The batch size is set to 32 and the maximum number of iterations is set to 500. An early stopping mechanism is introduced during the iterative training process to prevent overfitting. The early stopping mechanism includes stopping the iterative training if the loss value of the hybrid loss function does not decrease during 15 consecutive rounds of iterative training, saving the current optimal model parameters, and obtaining the trained dehazed network model. Otherwise, the parameters of the last iteration are used as the model parameters of the trained dehazed network model.
[0059] The test set is input into the trained dehazing network model to generate the corresponding clear dehazing image. The peak noise ratio and structural similarity between the clear dehazing image and the real fog-free image are calculated. The peak noise threshold is set to 25dB and the structural similarity threshold is set to 0.8. If the peak noise ratio exceeds 25dB and the structural similarity exceeds 0.8, the trained dehazing network model is obtained; otherwise, the iterative training is repeated.
[0060] This application introduces fog mask as a weighting factor into the loss calculation, and constructs a comprehensive loss function that includes a fog weighting mechanism. During model training, higher weights are dynamically assigned to pixel or structural errors in foggy areas, thereby guiding the defogging network to concentrate more optimization resources on the areas that are most difficult to process and have the most significant impact on the final visual effect. This effectively solves the problem that the traditional uniform loss function is insufficient for optimizing foggy areas.
[0061] In some embodiments, the formula for calculating the comprehensive loss function is: L_total = α×L1'+β×L_S' +γ×L_p+δ×L_G; where: L_total is the total loss function, α, β, γ, and δ are hyperparameters used to balance the contributions of each loss, L1' is pixel difference, L_S' is structural difference, L_p is perceptual difference, and L_G is texture difference; wherein, both the pixel difference L1' and the structural difference L_S' introduce a fog weighting mechanism, and the loss function of the fog weighting mechanism is: L_weighted=L_original⊙(1+λM); where: L_weighted is the fog weighting loss function, L_original is the original pixel-level loss map, λ is the weighting factor, ⊙ is element-wise multiplication, and M is the binary fog mask.
[0062] Specifically, to achieve optimal results in image dehazing tasks, especially in recovering clear details in dense fog regions, this application designs a comprehensive loss function. This function integrates multiple losses to ensure that the generated images perform well in terms of pixel accuracy, structural integrity, semantic meaning, and visual realism. Furthermore, this application introduces a fog region weighting mechanism, enabling the model to focus on learning the dense fog regions that are most critical for dehazing.
[0063] Construct a fog-weighted loss function:
[0064] To enhance the model's dehazing performance in dense fog regions, this application defines a fog-weighted loss function. This function applies fog-specific weights to the base loss, making the model focus more on optimizing dense fog areas. The fog-weighted loss formula is as follows:
[0065] L_weighted=L_original⊙(1+λM);
[0066] In the formula: L_original is the original pixel-level loss map; M is the binary haze mask, where haze pixels are 1 and otherwise 0; λ is the weighting factor; ⊙ represents element-wise multiplication.
[0067] Pixel difference L1': This measures the difference between the dehazed image and the true haze-free image at the pixel level. By introducing the pixel difference L1', the pixel distribution of the clear dehazed image is made as close as possible to the true haze-free image, thus improving the image quality of the clear dehazed image. Its calculation formula is as follows:
[0068] L1'=(1 / N)×Σ[(1+λ×M_i)×|I_i-J_i|];
[0069] In the formula: I is the dehazed image generated by the model; J is the real, fog-free reference image; I_i and J_i are the pixel values at position i in the two images, respectively; N is the total number of pixels in the image; M is a binary haze mask, with 1 for dense fog areas and 0 for non-fog areas; λ is a hyperparameter that controls the magnitude of the additional weights on fog areas.
[0070] The structural difference loss term L_S' is used to calculate weighted structural similarity across multiple image resolutions. By introducing L_S', the structural differences between the clear dehazed image and the true haze-free image are quantified, addressing potential blurring or distortion in the dehazing network model output while preserving structural features such as edges and textures of the real environment. Its calculation formula is as follows:
[0071] L_S'= (1 / N)×Σ[(1+λ×M_i)×(1-SSIM_i(I,J))];
[0072] In the formula: N is the total number of pixels in the image; M is a binary haze mask, with 1 for dense fog areas and 0 for non-fog areas; λ is a hyperparameter that controls the magnitude of the additional weight on fog areas; SSIM_i(I,J) is the structural similarity value calculated within a local window centered on pixel i.
[0073] The perceptual difference loss term L_p is used to perceive the differences in high-level semantic features between the generated image and the real image. By introducing the perceptual difference L_p, the high-level features of the clear dehazed image and the real haze-free image are compared, solving the problem that the clear dehazed image may have an unnatural overall visual effect due to excessive pursuit of pixel value matching, thus improving the naturalness of the clear dehazed image and making it more in line with human visual perception. Its calculation formula is as follows:
[0074] L_p=(1 / N)×Σ(1 / (C_i×H_i×W_i))×||φ(I)_i-φ(J)_i||1;
[0075] In the formula: I is the dehazed image generated by the model; J is the real, hazy reference image; I_i and J_i are the pixel values of the two images at position i, respectively; N is the total number of pixels in the image; C_i, H_i, and W_i are the number of channels, height, and width of the i-th feature layer, respectively; φ(·) represents the feature extraction function of the pre-trained network.
[0076] Texture difference loss term L_a: Used to enhance the overall realism of the generated image. By introducing the texture difference L_a, the clear dehazed image is forced to approximate the real haze-free image in terms of pixels, texture structure, and detail quality. This solves the problems of unclear texture, unnatural light and shadow transitions, and loss of key details in the dehazed image, thus improving the realism of the clear dehazed image. Its calculation formula is:
[0077] L_G = -E[logD(G(z))];
[0078] L_D=-E[logD(x)]-E[log(1-D(G(z)))];
[0079] In the formula: L_G is the adversarial loss of L_D, representing texture difference; E[...] represents the expectation value; D is the discriminator; G is the generator; x is the real fog-free image; z is the input foggy image.
[0080] Finally, all the above loss terms are combined to form the overall objective function for model training. The formula for the overall loss function is:
[0081] L_total =α×L1'+β×L_S' +γ×L_p+δ×L_G;
[0082] In the formula: L_total is the total loss function, α, β, γ, and δ are hyperparameters used to balance the contributions of each loss, L1' is pixel difference, L_S' is structural difference, L_p is perceptual difference, and L_G is texture difference.
[0083] Through this comprehensive loss function, the dehazing model of this application can recover fog-free images with clear structure, correct semantics and realistic visuals while ensuring pixel-level accuracy, and is particularly good at handling the challenges of dense fog areas.
[0084] Please refer to Figure 3On the other hand, the present invention also provides an image dehazing system for complex environments, comprising: an acquisition module 10, used to acquire an original image containing non-uniform fog and preprocess the original image; a fog enhancement module 20, used to comprehensively determine the dense fog region in the image based on the saturation value, brightness value, and contrast value of the original image, construct a fog mask based on the dense fog region, and use the fog mask to enhance the fog edge and texture structure of the dense fog region in the original image; a dehazing module 30, used to construct a fog dataset using the feature-enhanced original image and the corresponding fog mask, input the fog dataset into a dehazing network model for iterative training, use the trained dehazing network model to perform image dehazing and restoration, and generate a clear dehazing image; and a model optimization module 40, used to construct a comprehensive loss function containing a fog weighting mechanism based on the pixel difference, structural difference, perceptual difference, and texture difference between the clear dehazing image and the real fog-free image, and optimize the dehazing network model until it meets the preset model performance evaluation criteria.
[0085] On the other hand, the present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described image dehazing method under complex environments.
[0086] On the other hand, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the above-described image dehazing method under complex environments.
[0087] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0088] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, database, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0089] The above are merely embodiments of the present invention and do not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention's specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. An image defogging method in a complex environment, characterized by the steps of The method comprises the following steps: acquiring an original image containing non-uniform fog, and preprocessing the original image; determining a dense fog region in the image based on saturation, brightness and contrast values of the original image, constructing a fog area mask based on the dense fog region, and enhancing the dense fog region in the original image using the fog area mask in terms of fog area edge and texture structure; constructing a fog area data set using the original image after feature enhancement and the corresponding fog area mask, inputting the fog area data set into a de-fogging network model for iterative training, using the trained de-fogging network model for image de-fogging and recovery, and generating a clear de-fogging image; the construction steps of the de-fogging network model specifically comprise: constructing a D-Transformer network based on a deformable convolution DCNv4, inputting the fog area mask and the original image after feature enhancement into the D-Transformer network at the same time, and obtaining image enhancement features; generating a corresponding attention map for the fog area mask through an attention sub-module in the D-Transformer network; performing channel multiplication operation on the attention map and the image enhancement features to enable the D-Transformer network to learn fog area features, thereby outputting a preliminary de-fogging image; constructing an R-Transformer network based on a Retinex algorithm, inputting the preliminary de-fogging image into the R-Transformer network, and obtaining image weighting features; performing channel multiplication operation again on the image weighting features and the attention map to enable the R-Transformer network to preferentially restore fog area colors and details, and finally output a clear de-fogging image; constructing a comprehensive loss function containing a fog area weighting mechanism based on pixel differences, structural differences, perceptual differences and texture differences between the clear de-fogging image and a real fog-free image, and optimizing the de-fogging network model until a preset model performance evaluation standard is met.
2. The image defogging method in a complex environment according to claim 1, wherein, The step of determining the dense fog region in the image based on the saturation, brightness and contrast values of the original image specifically comprises: performing HSV space conversion on the original image; acquiring saturation, brightness and contrast values of the original image, and setting saturation, brightness and contrast thresholds; determining a region with a saturation value lower than the saturation threshold, a brightness value higher than the brightness threshold and a contrast value lower than the contrast threshold as the dense fog region.
3. The image defogging method in a complex environment according to claim 2, characterized in that, The step of constructing a fog area mask based on the dense fog region specifically comprises: performing edge extraction on the original image using an edge detection algorithm to obtain an edge texture map, and performing intersection operation on the edge texture map and the dense fog region to obtain the fog area mask.
4. The image defogging method in a complex environment according to claim 1, characterized in that, The step of enhancing the dense fog region in the original image using the fog area mask in terms of fog area edge and texture structure specifically comprises: performing pixel mapping on the fog area mask and the original image to locate the dense fog region in the original image; Linear multiplication is performed on the saturation channel of the HSV space to enhance the vividness of the fog area, and then local histogram equalization is performed on the saturation channel of the same HSV space to enhance the contrast of the fog area, to obtain a visually enhanced image; The visually enhanced image is guided filtered using the original image as a guide image, so as to retain edges and textures in the enhanced area, to obtain a structure-enhanced image; The structure-enhanced image is fused with the original image to obtain a target enhanced image.
5. The image defogging method in a complex environment according to claim 1, characterized in that, The step of constructing a comprehensive loss function including a fog area weighting mechanism based on pixel differences, structural differences, perceptual differences and texture differences between the clear defogging image and the real fog-free image specifically comprises: Obtaining pixel differences, structural differences, perceptual differences and texture differences between the clear defogging image and the real fog-free image; Introducing a fog area mask as a weight factor into the calculation of at least one loss to give a higher optimization weight to the heavy fog area in model training; Based on the preset difference weight, the pixel difference, the structural difference, the perceptual difference and the texture difference are weighted and summed to construct a comprehensive loss function.
6. The image defogging method in a complex environment according to claim 5, characterized in that, The calculation formula of the comprehensive loss function is: L_total =α×L1'+β×L_S' +γ×L_p+δ×L_G; In the formula, L_total is a total loss function, α, β, γ, δ are hyperparameters for balancing the contribution of each loss, L1' is a pixel difference, L_S' is a structural difference, L_p is a perceptual difference, and L_G is a texture difference; Among them, the pixel difference L1' and the structural difference L_S' both introduce a fog area weighting mechanism, and the loss function of the fog area weighting mechanism is: L_weighted=L_original⊙(1+λM); In the formula, L_weighted is a fog area weighted loss function, L_original is an original pixel-level loss graph, λ is a weight factor, ⊙ is an element-level multiplication, and M is a binary fog area mask.
7. An image defogging system in a complex environment, characterized in that, It comprises: An acquisition module is configured to acquire an original image containing non-uniform fog and pre-process the original image; A fog area enhancement module is configured to determine a heavy fog area in the image based on saturation values, brightness values and contrast values of the original image, construct a fog area mask based on the heavy fog area, and enhance the edge and texture structure of the heavy fog area in the original image using the fog area mask; A defogging module is configured to construct a fog area dataset using the original image with enhanced features and the corresponding fog area mask, input the fog area dataset into a defogging network model for iterative training, use the trained defogging network model for image defogging and restoration, and generate a clear defogging image. The construction steps of the defogging network model specifically comprise: A D-Transformer network is constructed based on a deformable convolution DCNv4, the fog area mask and the original image with enhanced features are simultaneously input into the D-Transformer network, and image enhancement features are obtained. The attention sub-module in the D-Transformer network generates a corresponding attention map from the fog area mask; The attention map and the image enhancement feature are subjected to channel multiplication operation, so that the D-Transformer network learns the fog area feature, thereby outputting a preliminary dehazing image; An R-Transformer network is constructed based on a Retinex algorithm, the preliminary dehazing image is input into the R-Transformer network, and an image weighted feature is obtained; The image weighted feature and the attention map are subjected to channel multiplication operation again, so that the R-Transformer network preferentially restores the color and details of the fog area, and finally outputs a clear dehazing image; A model optimization module is configured to construct a comprehensive loss function containing a fog area weighting mechanism based on pixel difference, structure difference, perception difference and texture difference between the clear dehazing image and a real haze-free image, and optimize the dehazing network model until a preset model performance evaluation standard is met.
8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that, The processor executes the computer program to implement the steps of the image dehazing method in complex environment according to any one of claims 1-6.
9. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the image dehazing method in complex environment according to any one of claims 1-6.
Citation Information
Patent Citations
Image defogging method of convolutional neural network based on fusion Transform
CN116012253A
Defogging method and device based on infrared light and visible light image fusion
CN120655540A