Scale-adaptive Retinex algorithm image defogging method and device
Through the combination of scale-adaptive Retinex algorithm and Gaussian filter, the problem of poor image dehazing effect in low-brightness foggy environment is solved, better color recovery and detail retention are achieved, and the image dehazing quality and visual effect are improved. .
Patent Information
- Application Number
- CN202410713625.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-06-04
AI Technical Summary
Existing image defogging methods are less effective in low-brightness foggy environments, prone to color distortion and loss of details, and cannot effectively extract image information.
The scale-adaptive Retinex algorithm is used to obtain the target illumination image and reflection image of the image to be dehazed, determine the adaptive Gaussian scale parameters, construct a Gaussian filter, smooth the noise on the target illumination image based on the Retinex algorithm, and combine the target reflection image , determine the dehazed image, and use the multi-scale Retinex algorithm for weighted summation to improve the color recovery effect.
It effectively compresses the dynamic range of images, maintains good color recovery effects and detail information, improves the quality and visual effects of defogging images, and provides more reliable data and high automation levels for industrial production.
Smart Images

Figure CN118279196B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image processing, and in particular relates to a scale-adaptive Retinex algorithm image defogging method and device. Background Art
[0002] In recent years, with the continuous development of image processing, using images to obtain information has become an important means. For example, high-quality images are used for target detection. However, images taken in adverse environments such as haze, fog, smoke and other outdoor scenes under adverse weather conditions are usually affected by factors such as ambient brightness, haze, smoke, etc., resulting in blurred images, low contrast, dim colors, brightness offset and lack of details.
[0003] Dehazing an image can significantly increase the contrast of an object and correct the color distortion caused by air light. However, existing image dehazing methods are less effective in low-brightness foggy environments, and their dehazing results are prone to color distortion, detail loss, and other problems, making it impossible to effectively extract image information.
[0004] Therefore, there is an urgent need to provide a new image dehazing method. Summary of the invention
[0005] The present invention provides a scale-adaptive Retinex algorithm image defogging method and device, which are used to solve the defects in the prior art.
[0006] The present invention provides a scale-adaptive Retinex algorithm image defogging method, comprising:
[0007] Acquire an image to be defogged, and extract a target illumination image and a target reflection image of the image to be defogged;
[0008] Determine a filter window of the image to be defogged, and use the filter window to traverse the image to be defogged, and determine an adaptive Gaussian scale parameter based on an absolute difference in pixel values between a central pixel point and adjacent pixels within the filter window;
[0009] Based on the adaptive Gaussian scale parameter, a Gaussian filter is constructed, and based on the Retinex algorithm, the Gaussian filter is used to smooth the noise of the target illumination image to obtain a target smoothing result, and based on the target smoothing result and the target reflection image, the target defogging image corresponding to the image to be defogged is determined.
[0010] According to a scale-adaptive Retinex algorithm image defogging method provided by the present invention, based on the Retinex algorithm, the Gaussian filter is used to smooth the noise of the target illumination image to obtain a target smoothing result, and based on the target smoothing result and the target reflection image, the target defogging image corresponding to the image to be defogged is determined, specifically comprising:
[0011] Based on the single-scale Retinex algorithm, using the Gaussian filter, smoothing the noise of the target illumination image to obtain the target smoothing result, and determining the target defogging image based on the target smoothing result and the target reflection image;
[0012] or,
[0013] Based on the adaptive Gaussian scale parameter, construct a plurality of Gaussian filters;
[0014] Traversing each Gaussian filter, based on a single-scale Retinex algorithm, using each traversed Gaussian filter to respectively smooth the noise of the target illumination image, obtaining a smoothing result corresponding to each Gaussian filter, and determining a plurality of candidate defogging images based on each smoothing result and the target reflection image;
[0015] The target defogging image is determined based on the weighted summation results of the multiple candidate defogging images.
[0016] According to a scale-adaptive Retinex algorithm image defogging method provided by the present invention, the target defogging image is determined based on the weighted summation result of the multiple candidate defogging images, specifically including:
[0017] Calculating a color restoration factor based on the pixel values of each pixel on the image to be dehazed corresponding to different channels and the sum of the pixel values of each pixel on the image to be dehazed corresponding to all channels;
[0018] The weighted sum result is adjusted based on the color restoration factor to obtain the target defogging image.
[0019] According to a scale-adaptive Retinex algorithm image defogging method provided by the present invention, the determining of the filter window of the image to be defogged specifically includes:
[0020] Determine the noise density of the image to be dehazed;
[0021] Based on the noise density, the filtering window is determined.
[0022] According to a scale-adaptive Retinex algorithm image defogging method provided by the present invention, the determining of the noise density of the image to be defogged specifically includes:
[0023] Determine the target number of pixels in the image to be defogged whose pixel values are 0 or 255;
[0024] The noise density is determined based on the target number of pixels and the total number of pixels in the image to be defogged.
[0025] According to a scale-adaptive Retinex algorithm image defogging method provided by the present invention, the filtering window is determined based on the noise density, specifically comprising:
[0026] If the noise density is less than a preset threshold, determining that the filter window is a rectangular window with a side length of a first number of pixels;
[0027] If the noise density is greater than or equal to the preset threshold, determining that the filtering window is a rectangular window with a side length of a second number of pixels;
[0028] The first number of pixels is smaller than the second number of pixels.
[0029] According to a scale-adaptive Retinex algorithm image defogging method provided by the present invention, extracting a target illumination image and a target reflection image of the image to be defogged specifically includes:
[0030] Inputting the image to be defogged into an image decomposition model to obtain the target illumination image and the target reflection image output by the image decomposition model;
[0031] The image decomposition model is trained based on the following steps:
[0032] Inputting haze image samples and normal image samples into an initial decomposition model respectively, and obtaining a first illumination map and a first reflection map corresponding to the haze image samples, and a second illumination map and a second reflection map corresponding to the normal image samples output by the initial decomposition model;
[0033] Calculating an image reconstruction loss based on the haze image sample, the normal image sample, the first illumination map, the first reflection map, the second illumination map, and the second reflection map;
[0034] Calculating a constant reflection loss based on the first reflection map and the second reflection map;
[0035] Calculating an illumination smoothing loss based on the first illumination map, the first reflection map, the second illumination map, and the second reflection map;
[0036] Based on the image reconstruction loss, the invariant reflection loss and the illumination smoothness loss, the model loss is calculated, and based on the model loss, the initial decomposition model is trained to obtain the image decomposition model.
[0037] The present invention also provides a scale-adaptive Retinex algorithm image defogging device, comprising:
[0038] An image extraction module is used to obtain the image to be defogged, and to extract a target illumination image and a target reflection image of the image to be defogged;
[0039] A scale parameter determination module, used to determine a filter window of the image to be defogged, and use the filter window to traverse the image to be defogged, and determine an adaptive Gaussian scale parameter based on the absolute difference in pixel values between a central pixel point and adjacent pixels in the filter window;
[0040] The image defogging module is used to construct a Gaussian filter based on the adaptive Gaussian scale parameter, and use the Gaussian filter to smooth the noise of the target illumination image based on the Retinex algorithm to obtain a target smoothing result, and determine the target defogging image corresponding to the image to be defogged based on the target smoothing result and the target reflection image.
[0041] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the scale-adaptive Retinex algorithm image defogging method as described in any one of the above is implemented.
[0042] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the scale-adaptive Retinex algorithm image defogging method as described in any one of the above is implemented.
[0043] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the scale-adaptive Retinex algorithm image defogging method as described in any one of the above is implemented.
[0044] Compared with the prior art, the present invention has the following beneficial effects:
[0045] The present invention provides a scale-adaptive Retinex algorithm image defogging method and device. The method decomposes the image to be defogged to obtain a target illumination image, and can construct a Gaussian filter through the determined adaptive Gaussian scale parameters. Based on the Retinex algorithm, the Gaussian filter is used to smooth the noise of the target illumination image, so that the obtained target smoothing result is combined with the target reflection image, which can more effectively compress the dynamic range of the image to be defogged, maintain good color restoration effect and detail information, improve the quality of the target defogging image and enhance the visual effect, and provide more reliable data and a higher level of automation for industrial production and manufacturing. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on the drawings in the following description without paying any creative work.
[0047] Figure 1 It is a schematic diagram of the process of the scale-adaptive Retinex algorithm image defogging method provided by the present invention;
[0048] Figure 2 It is a structural schematic diagram of a scale-adaptive Retinex algorithm image defogging device provided by the present invention;
[0049] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] Since the existing image defogging methods are less effective in low-brightness foggy environments, the defogging results are prone to color distortion and detail loss, resulting in inaccurate extracted image information. To this end, a new image defogging method is provided in an embodiment of the present invention to improve the visual environment of advanced visual tasks in foggy weather.
[0052] Figure 1 A scale-adaptive Retinex algorithm image defogging method is provided in an embodiment of the present invention. Figure 1 As shown, the method includes:
[0053] S1, obtaining an image to be defogged, and extracting a target illumination image and a target reflection image of the image to be defogged;
[0054] S2, determining a filter window of the image to be defogged, and using the filter window to traverse the image to be defogged, and determining an adaptive Gaussian scale parameter based on an absolute difference in pixel values between a central pixel point and adjacent pixels within the filter window;
[0055] S3, based on the adaptive Gaussian scale parameter, construct a Gaussian filter, and based on the Retinex algorithm, use the Gaussian filter to smooth the noise of the target illumination image to obtain a target smoothing result, and based on the target smoothing result and the target reflection image, determine the target defogging image corresponding to the image to be defogged.
[0056] Specifically, the scale-adaptive Retinex algorithm image defogging method provided in the embodiment of the present invention is executed by a scale-adaptive Retinex algorithm image defogging device, which can be configured in a computer, which can be a local computer or a cloud computer. The local computer can be a computer, a tablet, etc., which is not specifically limited here.
[0057] First, step S1 is performed to obtain an image to be defogged. The image to be defogged can be an image taken on a foggy day, a normal brightness image in a daytime, a sunny day, or a low brightness image in a nighttime, a cloudy day, etc., which is not specifically limited here.
[0058] The image to be defogged may be a color image acquired by an image acquisition device, which may be a camera and may be mounted on a robot.
[0059] Since the Retinex theory can simulate human color perception, the image to be defogged can be decomposed into the target illumination image and the target reflection image according to the Retinex theory. Let S represent the image to be defogged, then:
[0060] (1)
[0061] in, is the pixel point in the image to be dehazed The pixel value at is the pixel point in the target illumination image The pixel value at is the pixel point in the target reflection image The pixel value at .
[0062] Therefore, according to the Retinex theory, the target illumination image and target reflection image of the image to be dehazed can be extracted through artificial intelligence (AI) methods.
[0063] Then, step S2 is performed to determine the filter window W of the image to be defogged. The size of the filter window W can be preset as needed, or can be determined according to the noise density of the image to be defogged, which is not specifically limited here. The filter window W can be a square window with equal length and width. For example, the size of the filter window W can be expressed as N×N, and N can be 3, 5, 7, etc.
[0064] The filter window can be moved on the image to be defogged. With the filter window, the image to be defogged can be traversed to calculate the absolute difference between the pixel values of the central pixel point and the adjacent pixel points in the filter window. The absolute difference can be the absolute value of the difference between the pixel value of the central pixel point and the pixel value of the adjacent pixel point. Here, the central pixel point is the pixel point on the image to be defogged corresponding to the center point of the filter window, and the adjacent pixel points are the pixel points on the image to be defogged corresponding to the adjacent points of the center point of the filter window. The central pixel point can be one, and the adjacent pixel points can include multiple adjacent pixel points, which are determined by the size of the filter window. For example, there can be M adjacent pixel points, and the value of M can be 4, 12, 24, etc.
[0065] The absolute difference between the pixel values of the central pixel and the adjacent pixels in the filter window can be expressed by the following formula (2):
[0066] (2)
[0067] in, The center pixel The pixel value of Neighboring pixels The pixel value of is half the side length of the filter window, is the number of pixels between the adjacent pixel points and the central pixel point in the length direction of the image to be dehazed, It is the number of pixels between the adjacent pixel points and the central pixel point in the width direction of the image to be dehazed.
[0068] After that, the absolute difference of the pixel value is added to a basic scale parameter to obtain an adaptive Gaussian scale parameter , as shown in formula (3):
[0069] (3)
[0070] in, It is in pixels The adaptive Gaussian scaling parameter at By placing pixels As the center pixel , calculated using formula (2). is a basic scale parameter and can be pre-set according to the overall noise level of the image to be dehazed. is a scaling factor used to adjust the influence of the absolute difference of pixel values on the adaptive Gaussian scale parameter.
[0071] It will change according to the change of local contrast of the image to be dehazed. For the area with high contrast in the image to be dehazed, The value will be smaller to retain more details; for areas with low contrast in the image to be dehazed, Larger values will smooth out the noise.
[0072] Finally, step S3 is executed to construct a Gaussian filter using the adaptive Gaussian scale parameter. The Gaussian filter is shown in formula (4):
[0073] (4)
[0074] in, Pixel The value of the Gaussian filter at , λ is a constant, which is determined by the normalization result of the adaptive Gaussian scale parameter.
[0075] The Retinex algorithm is used to smooth the noise of the target illumination image using a Gaussian filter to obtain a target smoothing result. Based on the target smoothing result and the target reflection image, the target defogging image corresponding to the image to be defogged is determined. Among them, the Retinex algorithm can include a single-scale Retinex (Single Scale Retinex, SSR) algorithm and a multi-scale Retinex (Multi Scale Retinex, MSR) algorithm. The single-scale Retinex algorithm can directly obtain the target defogging image, and the multi-scale Retinex algorithm is an improved single-scale Retinex algorithm. The target defogging image can be obtained by weighted summing the candidate defogging images obtained by multiple single-scale Retinex algorithms. The multi-scale Retinex algorithm can more effectively avoid color distortion and obtain the dynamic range of image compression.
[0076] The scale-adaptive Retinex algorithm image defogging method provided in the embodiment of the present invention first obtains the image to be defogged, and extracts the target illumination image and the target reflection image of the image to be defogged; then determines the filtering window of the image to be defogged, and uses the filtering window to traverse the image to be defogged, and determines the adaptive Gaussian scale parameter based on the absolute difference of the pixel value between the central pixel point and the adjacent pixel points in the filtering window; finally, based on the adaptive Gaussian scale parameter, constructs a Gaussian filter, and based on the Retinex algorithm, uses the Gaussian filter to smooth the noise of the target illumination image to obtain a target smoothing result, and determines the target defogging image corresponding to the image to be defogged based on the target smoothing result and the target reflection image. This method decomposes the image to be defogged to obtain a target illumination image. A Gaussian filter can be constructed by determining the adaptive Gaussian scale parameters. Based on the Retinex algorithm, the Gaussian filter is used to smooth the noise of the target illumination image. The target smoothing result is combined with the target reflection image. This method can more effectively compress the dynamic range of the image to be defogged, maintain good color restoration effect and detail information, improve the quality of the target defogging image and enhance the visual effect, and provide more reliable data and a higher level of automation for industrial production and manufacturing.
[0077] On the basis of the above embodiment, the Retinex algorithm is used to use the Gaussian filter to smooth the noise of the target illumination image to obtain a target smoothing result, and based on the target smoothing result and the target reflection image, the target defogging image corresponding to the image to be defogged is determined, specifically including:
[0078] Based on the single-scale Retinex algorithm, using the Gaussian filter, smoothing the noise of the target illumination image to obtain the target smoothing result, and determining the target defogging image based on the target smoothing result and the target reflection image;
[0079] or,
[0080] Based on the adaptive Gaussian scale parameter, construct a plurality of Gaussian filters;
[0081] Traversing each Gaussian filter, based on a single-scale Retinex algorithm, using each traversed Gaussian filter to respectively smooth the noise of the target illumination image, obtaining a smoothing result corresponding to each Gaussian filter, and determining a plurality of candidate defogging images based on each smoothing result and the target reflection image;
[0082] The target defogging image is determined based on the weighted summation results of the multiple candidate defogging images.
[0083] Specifically, in the embodiment of the present invention, a single-scale Retinex algorithm can be used to smooth the noise of the target illumination image with the help of a Gaussian filter to obtain a target smoothing result. Then, the target smoothing result and the target reflection image can be used to obtain a target defogging image. It can be understood that the single-scale Retinex algorithm can process each channel of the defogging image separately to obtain the target defogging image of each channel.
[0084] For example, for the channel , R is the red channel, G is the green channel, and B is the blue channel. The single-scale Retinex algorithm can be expressed as:
[0085] (5)
[0086] in, is the pixel point in the tth channel of the image to be dehazed The pixel value at is the pixel point in the tth channel of the image to be dehazed The value of the Gaussian filter at is the pixel in the target illumination image of the tth channel of the image to be dehazed The pixel value at . The target defogging image of the tth channel of the image to be defogged obtained by the single-scale Retinex algorithm is at pixel point The pixel value at . is the target smoothing result of the tth channel of the image to be dehazed.
[0087] In addition, a multi-scale Retinex algorithm can also be used to determine the target defogging image. , the multi-scale Retinex algorithm can be expressed as:
[0088] (6)
[0089] in, is the target defogging image of the tth channel of the image to be defogged obtained by the single-scale Retinex algorithm with a scale of s at pixel point The pixel value at is the target defogging image of the tth channel of the image to be defogged obtained by the multi-scale Retinex algorithm at pixel point The pixel value at is the weight coefficient corresponding to the single-scale Retinex algorithm with scale s, and .
[0090] On the basis of the above embodiment, the step of determining the target defogging image based on the weighted sum of the multiple candidate defogging images specifically includes:
[0091] Calculating a color restoration factor based on pixel values of different channels corresponding to each pixel point on the image to be dehazed and the sum of pixel values of all channels corresponding to each pixel point on the image to be dehazed;
[0092] The weighted sum result is adjusted based on the color restoration factor to obtain the target defogging image.
[0093] Specifically, since the multi-scale Retinex algorithm cannot achieve perfect results, there are certain defects in the local or global colors of the image to be dehazed, and the color fidelity is insufficient.
[0094] Therefore, after the multi-scale Retinex algorithm obtains the weighted sum of multiple candidate defogging images, the pixel points of the tth channel of the image to be defogged can be introduced. Color restoration factor at , and through the color restoration factor The weighted summation result Adjustment can ensure the color fidelity of the target dehazed image.
[0095] By using the color restoration factor The weighted summation result The adjustment process can be expressed by formula (7):
[0096] (7)
[0097] in, The target defogging image of the tth channel of the image to be defogged is obtained by adjusting the color restoration factor at pixel point The pixel value at .
[0098] It can be determined by the following formula (8):
[0099] (8)
[0100] in, is an adjustment parameter used to control the degree of color restoration. Indicates the tth channel of the image to be dehazed at pixel point The pixel value at Indicates the pixel points of each channel of the image to be dehazed The sum of the pixel values at , n is any channel of the image to be dehazed, Indicates the nth channel of the image to be dehazed at pixel point The pixel value at .
[0101] On the basis of the above embodiment, determining the filter window of the image to be defogged specifically includes:
[0102] Determine the noise density of the image to be dehazed;
[0103] Based on the noise density, the filtering window is determined.
[0104] Specifically, when determining the filter window of the image to be defogged, the noise density η of the image to be defogged can be determined first, where the noise density is the percentage of noise pixels in the image to be defogged. Here, pixels with pixel values of 0 or 255 in the image to be defogged can be used as noise pixels.
[0105] After that, the size of the filter window of the image to be defogged can be determined by using the value of the noise density. For example, if the value of the noise density is small, a smaller filter window size can be selected; if the value of the noise density is large, a larger filter window size can be selected to avoid image blur.
[0106] Based on the above embodiment, determining the noise density of the image to be defogged specifically includes:
[0107] Determine the target number of pixels in the image to be defogged whose pixel values are 0 or 255;
[0108] The noise density is determined based on the target number of pixels and the total number of pixels in the image to be defogged.
[0109] Specifically, when determining the noise density of the image to be defogged, the target number of pixels with pixel values of 0 or 255 in the image to be defogged can be determined first. The target number of pixels can be obtained by calculating the noise density of each pixel in the image to be defogged. Identification information at Statistics show that:
[0110] (9)
[0111] in, is the pixel point in the image to be dehazed The pixel value at .
[0112] The noise density can be expressed as:
[0113] (10)
[0114] Among them, X is the number of pixels in the length direction of the image to be defogged, and Y is the number of pixels in the width direction of the image to be defogged. is the target number of pixels, is the total number of pixels in the image to be dehazed.
[0115] On the basis of the above embodiment, determining the filtering window based on the noise density specifically includes:
[0116] If the noise density is less than a preset threshold, determining that the filter window is a rectangular window with a side length of a first number of pixels;
[0117] If the noise density is greater than or equal to the preset threshold, determining that the filtering window is a rectangular window with a side length of a second number of pixels;
[0118] The first number of pixels is smaller than the second number of pixels.
[0119] Specifically, when determining the filter window, if the noise density is less than a preset threshold, it can be determined that the noise window is a rectangular window with a side length N being the first number of pixels. The preset threshold and the first number of pixels can be set as needed. For example, the preset threshold can be set to 20%, and the first number of pixels can be set to 3. At this time, the number M of adjacent pixels of the center pixel in the filter window can be 4, that is, the 4 adjacent pixels above, below, left, and right that are closest to the center pixel.
[0120] Furthermore, when the noise density is greater than or equal to a preset threshold, for example, the noise density is greater than or equal to 25%, it can be determined that the filter window is a rectangular window with a side length N of a second number of pixels. The second number of pixels is greater than the first number of pixels. For example, the second number of pixels can be 5, 7, etc.
[0121] When the second pixel number is 5, the number M of adjacent pixels of the central pixel in the filtering window can be 12, namely, the 8 adjacent pixels closest to the central pixel and the 4 adjacent pixels above, below, left and right of the central pixel with a distance of one pixel from the central pixel.
[0122] When the second number of pixels is 7, the number M of adjacent pixels of the center pixel in the filtering window can be 24, that is, the 8 adjacent pixels closest to the center pixel, the 12 adjacent pixels closest to the 8 adjacent pixels, and the 4 adjacent pixels above, below, left, and right of the center pixel that are two pixels apart.
[0123] On the basis of the above embodiment, extracting the target illumination image and the target reflection image of the image to be defogged specifically includes:
[0124] Inputting the image to be dehazed into an image decomposition model to obtain the illumination map output by the image decomposition model;
[0125] The image decomposition model is trained based on the following steps:
[0126] Inputting haze image samples and normal image samples into an initial decomposition model respectively, and obtaining a first illumination map and a first reflection map corresponding to the haze image samples, and a second illumination map and a second reflection map corresponding to the normal image samples output by the initial decomposition model;
[0127] Calculating an image reconstruction loss based on the haze image sample, the normal image sample, the first illumination map, the first reflection map, the second illumination map, and the second reflection map;
[0128] Calculating a constant reflection loss based on the first reflection map and the second reflection map;
[0129] Calculating an illumination smoothing loss based on the first illumination map, the first reflection map, the second illumination map, and the second reflection map;
[0130] Based on the image reconstruction loss, the invariant reflection loss and the illumination smoothness loss, the model loss is calculated, and based on the model loss, the initial decomposition model is trained to obtain the image decomposition model.
[0131] Specifically, when extracting the target illumination image and the target reflection image of the image to be defogged, an image decomposition model can be introduced, the image to be defogged is input into the image decomposition model, and the target illumination image and the target reflection image are output through the image decomposition model.
[0132] The image decomposition model can be obtained by training the initial decomposition model. The initial segmentation model can be a Decom-Net network structure, including an input convolution (Conv) layer, multiple convolution activation (Conv+Relu) layers, an output convolution layer, and a normalization (Sigmoid) layer.
[0133] The steps to train the initial decomposition model include:
[0134] The haze image samples and the normal image samples are respectively input into the initial decomposition model to obtain the first illumination map and the first reflection map corresponding to the haze image samples output by the initial decomposition model, and the second illumination map and the second reflection map corresponding to the normal image samples. The initial decomposition models corresponding to the haze image samples and the normal image samples share weights.
[0135] Using haze image samples, normal image samples, and the first illumination map , first reflection map , the second illumination map And the second reflection map , the image reconstruction loss can be calculated by the following formula (11):
[0136] (11)
[0137] in, is the image reconstruction loss, is the i-th type reflection map, is the first reflection image, is the second reflection map, is the j-th type of illumination map, is the first illumination map, is the second illumination map, is the j-th class image sample, is a haze image sample, is a normal image sample. is the weight parameter, when i≠j, Set to 0.001, when i=j, Set to 1.
[0138] Using the first illumination map and the second illumination map, the invariant reflection loss can be calculated by the following formula (12), and the invariant reflection loss can be used to constrain the consistency of the reflectivity of the image to be dehazed:
[0139] (12)
[0140] in, is the constant reflection loss.
[0141] Using the first illumination map, the first reflection map, the second illumination map, and the second reflection map, the illumination smoothing loss can be calculated using the following formula (13):
[0142] (13)
[0143] in, Smoothing loss for lighting. Gradient Include horizontal gradient and vertical gradient . is a coefficient for balancing the perceived strength of the structure. , The smoothness constraint is relaxed where the reflectance gradient is steep, i.e. where image structure is located and where illumination should be discontinuous.
[0144] Finally, by reconstructing the image , constant reflection loss and lighting smoothing loss Perform weighted summation to get the model loss :
[0145] (14)
[0146] in, and are weight coefficients, Set to 0.001, Set to 0.1.
[0147] Using model loss , the structural parameters of the initial decomposition model are iteratively optimized to obtain the image decomposition model.
[0148] like Figure 2 As shown, based on the above embodiment, an embodiment of the present invention provides a scale-adaptive Retinex algorithm image defogging device, comprising:
[0149] The image extraction module 21 is used to obtain the image to be defogged, and extract the target illumination image and the target reflection image of the image to be defogged;
[0150] A scale parameter determination module 22 is used to determine a filter window of the image to be defogged, and use the filter window to traverse the image to be defogged, and determine an adaptive Gaussian scale parameter based on the absolute difference between the pixel values of the central pixel point and the adjacent pixel points in the filter window;
[0151] The image defogging module 23 is used to construct a Gaussian filter based on the adaptive Gaussian scale parameter, and use the Gaussian filter to smooth the noise of the target illumination image based on the Retinex algorithm to obtain a target smoothing result, and determine the target defogging image corresponding to the image to be defogged based on the target smoothing result and the target reflection image.
[0152] On the basis of the above-mentioned embodiments, in the scale-adaptive Retinex algorithm image defogging device provided in the embodiments of the present invention, the image defogging module is specifically used for:
[0153] Based on the single-scale Retinex algorithm, using the Gaussian filter, smoothing the noise of the target illumination image to obtain the target smoothing result, and determining the target defogging image based on the target smoothing result and the target reflection image;
[0154] or,
[0155] Based on the adaptive Gaussian scale parameter, construct a plurality of Gaussian filters;
[0156] Traversing each Gaussian filter, based on a single-scale Retinex algorithm, using each traversed Gaussian filter to respectively smooth the noise of the target illumination image, obtaining a smoothing result corresponding to each Gaussian filter, and determining a plurality of candidate defogging images based on each smoothing result and the target reflection image;
[0157] The target defogging image is determined based on the weighted summation results of the multiple candidate defogging images.
[0158] On the basis of the above-mentioned embodiments, in the scale-adaptive Retinex algorithm image defogging device provided in the embodiments of the present invention, the image defogging module is specifically used for:
[0159] Calculating a color restoration factor based on the pixel values of each pixel on the image to be dehazed corresponding to different channels and the sum of the pixel values of each pixel on the image to be dehazed corresponding to all channels;
[0160] The weighted sum result is adjusted based on the color restoration factor to obtain the target defogging image.
[0161] On the basis of the above-mentioned embodiment, in the scale-adaptive Retinex algorithm image defogging device provided in the embodiment of the present invention, the scale parameter determination module is specifically used for:
[0162] Determine the noise density of the image to be dehazed;
[0163] Based on the noise density, the filtering window is determined.
[0164] On the basis of the above-mentioned embodiment, in the scale-adaptive Retinex algorithm image defogging device provided in the embodiment of the present invention, the scale parameter determination module is specifically used for:
[0165] Determine the target number of pixels in the image to be defogged whose pixel values are 0 or 255;
[0166] The noise density is determined based on the target number of pixels and the total number of pixels in the image to be defogged.
[0167] On the basis of the above-mentioned embodiment, in the scale-adaptive Retinex algorithm image defogging device provided in the embodiment of the present invention, the scale parameter determination module is specifically used for:
[0168] If the noise density is less than a preset threshold, determining that the filter window is a rectangular window with a side length of a first number of pixels;
[0169] If the noise density is greater than or equal to the preset threshold, determining that the filtering window is a rectangular window with a side length of a second number of pixels;
[0170] The first number of pixels is smaller than the second number of pixels.
[0171] On the basis of the above-mentioned embodiment, in the scale-adaptive Retinex algorithm image defogging device provided in the embodiment of the present invention, the image extraction module is specifically used for:
[0172] Inputting the image to be defogged into an image decomposition model to obtain the target illumination image and the target reflection image output by the image decomposition model;
[0173] The image decomposition model is trained based on the following steps:
[0174] Inputting haze image samples and normal image samples into an initial decomposition model respectively, and obtaining a first illumination map and a first reflection map corresponding to the haze image samples, and a second illumination map and a second reflection map corresponding to the normal image samples output by the initial decomposition model;
[0175] Calculating an image reconstruction loss based on the haze image sample, the normal image sample, the first illumination map, the first reflection map, the second illumination map, and the second reflection map;
[0176] Calculating a constant reflection loss based on the first reflection map and the second reflection map;
[0177] Calculating an illumination smoothing loss based on the first illumination map, the first reflection map, the second illumination map, and the second reflection map;
[0178] Based on the image reconstruction loss, the invariant reflection loss and the illumination smoothness loss, the model loss is calculated, and based on the model loss, the initial decomposition model is trained to obtain the image decomposition model.
[0179] Specifically, the functions of each module in the scale-adaptive Retinex algorithm image defogging device provided in the embodiment of the present invention correspond one-to-one to the operation flow of each step in the above-mentioned method embodiment, and the effects achieved are also consistent. Please refer to the above-mentioned embodiment for details, and no further description will be given in the embodiment of the present invention.
[0180] Figure 3 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 3 As shown, the electronic device may include: a processor (Processor) 310, a communication interface (Communications Interface) 320, a memory (Memory) 330 and a communication bus 340, wherein the processor 310, the communication interface 320, and the memory 330 communicate with each other through the communication bus 340. The processor 310 may call the logic instructions in the memory 330 to execute the scale-adaptive Retinex algorithm image defogging method provided in the above embodiments.
[0181] In addition, the logic instructions in the above-mentioned memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.
[0182] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the scale-adaptive Retinex algorithm image dehazing method provided in the above embodiments.
[0183] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the scale-adaptive Retinex algorithm image dehazing method provided in the above-mentioned embodiments.
[0184] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0185] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0186] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A scale-adaptive Retinex algorithm image defogging method, characterized in that: include: Acquire an image to be defogged, and extract a target illumination image and a target reflection image of the image to be defogged; Determine a filter window of the image to be defogged, and use the filter window to traverse the image to be defogged, and determine an adaptive Gaussian scale parameter based on an absolute difference in pixel values between a central pixel point and adjacent pixels within the filter window; Based on the adaptive Gaussian scale parameter, a Gaussian filter is constructed, and based on the Retinex algorithm, the Gaussian filter is used to smooth the noise of the target illumination image to obtain a target smoothing result, and based on the target smoothing result and the target reflection image, a target defogging image corresponding to the image to be defogged is determined; The absolute difference between the pixel values of the central pixel point and the adjacent pixel points in the filtering window is expressed by the following formula (2): (2) in, The center pixel The pixel value of Neighboring pixels The pixel value of is half the side length of the filter window, is the number of pixels between the adjacent pixel points and the central pixel point in the length direction of the image to be defogged, is the number of pixels between the adjacent pixel points and the central pixel point in the width direction of the image to be defogged; The absolute difference of the pixel values is added to a basic scale parameter to obtain an adaptive Gaussian scale parameter , as shown in formula (3): (3) in, It is in pixels The adaptive Gaussian scaling parameter at By placing pixels As the center pixel , calculated using formula (2); is the basic scale parameter, is a scaling factor used to adjust the influence of the absolute difference of pixel values on the adaptive Gaussian scale parameter, and M is the number of adjacent pixels.
2. The scale-adaptive Retinex algorithm image defogging method according to claim 1, characterized in that: The method further comprises: based on the Retinex algorithm, using the Gaussian filter to smooth the noise of the target illumination image to obtain a target smoothing result, and determining the target defogging image corresponding to the image to be defogged based on the target smoothing result and the target reflection image. Based on the single-scale Retinex algorithm, using the Gaussian filter, smoothing the noise of the target illumination image to obtain the target smoothing result, and determining the target defogging image based on the target smoothing result and the target reflection image; or, Based on the adaptive Gaussian scale parameter, construct a plurality of Gaussian filters; Traversing each Gaussian filter, based on the single-scale Retinex algorithm, using each traversed Gaussian filter to smooth the noise of the target illumination image respectively, to obtain a smoothing result corresponding to each Gaussian filter, and determining a plurality of candidate defogging images based on each smoothing result and the target reflection image; The target dehazed image is determined based on the weighted summation results of the multiple candidate dehazed images.
3. The scale-adaptive Retinex algorithm image defogging method according to claim 2, characterized in that: The step of determining the target defogging image based on the weighted sum of the multiple candidate defogging images specifically includes: Calculating a color restoration factor based on the pixel values of each pixel on the image to be dehazed corresponding to different channels and the sum of the pixel values of each pixel on the image to be dehazed corresponding to all channels; The weighted sum result is adjusted based on the color restoration factor to obtain the target defogging image.
4. The scale-adaptive Retinex algorithm image defogging method according to any one of claims 1 to 3, characterized in that: Determining the filter window of the image to be defogged specifically includes: Determine the noise density of the image to be dehazed; Based on the noise density, the filtering window is determined.
5. The scale-adaptive Retinex algorithm image defogging method according to claim 4, characterized in that: The determining of the noise density of the image to be defogged specifically includes: Determine the target number of pixels in the image to be defogged whose pixel values are 0 or 255; The noise density is determined based on the target number of pixels and the total number of pixels in the image to be defogged.
6. The scale-adaptive Retinex algorithm image defogging method according to claim 4, characterized in that: The determining the filtering window based on the noise density specifically includes: If the noise density is less than a preset threshold, determining that the filter window is a rectangular window with a side length of a first number of pixels; If the noise density is greater than or equal to the preset threshold, determining that the filtering window is a rectangular window with a side length of a second number of pixels; The first number of pixels is smaller than the second number of pixels.
7. The scale-adaptive Retinex algorithm image defogging method according to any one of claims 1 to 3, characterized in that: The step of extracting the target illumination image and the target reflection image of the image to be defogged specifically includes: Inputting the image to be defogged into an image decomposition model to obtain the target illumination image and the target reflection image output by the image decomposition model; The image decomposition model is trained based on the following steps: Inputting haze image samples and normal image samples into an initial decomposition model respectively, and obtaining a first illumination map and a first reflection map corresponding to the haze image samples, and a second illumination map and a second reflection map corresponding to the normal image samples output by the initial decomposition model; Calculating an image reconstruction loss based on the haze image sample, the normal image sample, the first illumination map, the first reflection map, the second illumination map, and the second reflection map; Calculating a constant reflection loss based on the first reflection map and the second reflection map; Calculating an illumination smoothing loss based on the first illumination map, the first reflection map, the second illumination map, and the second reflection map; Based on the image reconstruction loss, the invariant reflection loss and the illumination smoothness loss, the model loss is calculated, and based on the model loss, the initial decomposition model is trained to obtain the image decomposition model.
8. A scale-adaptive Retinex algorithm image defogging device, characterized in that: include: An image extraction module is used to obtain the image to be defogged, and to extract a target illumination image and a target reflection image of the image to be defogged; A scale parameter determination module, used to determine a filter window of the image to be defogged, and use the filter window to traverse the image to be defogged, and determine an adaptive Gaussian scale parameter based on the absolute difference in pixel values between a central pixel point and adjacent pixels in the filter window; An image defogging module is used to construct a Gaussian filter based on the adaptive Gaussian scale parameter, and use the Gaussian filter to smooth the noise of the target illumination image based on the Retinex algorithm to obtain a target smoothing result, and determine a target defogging image corresponding to the image to be defogged based on the target smoothing result and the target reflection image; The absolute difference between the pixel values of the central pixel point and the adjacent pixel points in the filtering window is expressed by the following formula (2): (2) in, The center pixel The pixel value of Neighboring pixels The pixel value of is half the side length of the filter window, is the number of pixels between the adjacent pixel points and the central pixel point in the length direction of the image to be defogged, is the number of pixels between the adjacent pixel points and the central pixel point in the width direction of the image to be defogged; The absolute difference of the pixel values is added to a basic scale parameter to obtain an adaptive Gaussian scale parameter , as shown in formula (3): (3) in, It is in pixels The adaptive Gaussian scaling parameter at By placing pixels As the center pixel , calculated using formula (2); is the basic scale parameter, is a scaling factor used to adjust the influence of the absolute difference of pixel values on the adaptive Gaussian scale parameter, and M is the number of adjacent pixels.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the scale-adaptive Retinex algorithm image defogging method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the scale-adaptive Retinex algorithm image defogging method according to any one of claims 1 to 7 is implemented.
