Simple and effective approach

Haze in images can be a real problem, and complex algorithms or neural networks are not always needed to remove it. I want to demonstrate an implementation of Robust Single Image Haze Removal Using Dark Channel Prior and Optimal Transmission Map and Adaptive Atmospheric Light in .NET.

Advantages of the approach:

  1. Simplicity and efficiency: The method, based on intuitive image processing principles, is easy to understand and simple to implement. Using only mathematical operations, and knowing their parameters, the final image will never contain unknown artifacts or “phantoms”. Working with an image will not look like digging through a black box with parameters of a neural network or a library with a closed algorithm.

  2. No dependence on training data: Does not require a complex training dataset, reducing costs and simplifying the process.

  3. High speed: Works quickly and does not require significant computing resources.

  4. Transparency and interpretability: An image processing technique that is easy to understand, making it easier to explain and justify the results.

  5. Versatility: Works well on a variety of image types and lighting conditions without the need for complex re-tuning.

Tools used:

To solve the haze removal problem, we use the EmguCV library, a wrapper for OpenCV in .NET. This tool provides convenient access to a wide range of image and video processing functions, and matrices in general. Moreover, the syntax for working with CPU and GPU is approximately the same: new Mat() or new GpuMat(). But there is a difference in calling methods, which is inherited from OpenCV. And when working with GpuMat, you need to more carefully monitor garbage collection, or implement your own interface with GC, or you will have to constantly use using. There is an issue on github about clearing GpuMat memory, but it is not closed yet.

Atmospheric light diagram was kindly provided mirasnowfox

The main components of this method include:

  1. Atmospheric light assessment:

using quadratic expansion

select the area with the highest brightness

This way we will most likely avoid extraneous light sources, for example, car headlights, and speed up subsequent sorting. Next, for the resulting area, we find its dark channel: a simple but effective way to evaluate information about the depth of the scene. Implementation example


private Mat ComputeDarkChannelPatch(Image<Bgr, float> srcImage, int patch)
        {
            var bgrChannels = srcImage.Clone().Mat.Split();
            var darkChannel = new Mat();
            CvInvoke.Min(bgrChannels[0], bgrChannels[1], darkChannel);
            CvInvoke.Min(darkChannel, bgrChannels[2], darkChannel);
            CvInvoke.Erode(darkChannel, darkChannel, null, new Point(-1, -1), patch, BorderType.Reflect101, default);
            return darkChannel;
        }

Formula d(x,y)=min(R(x,y),B(x,y),G(x,y)) Where R(x,y) , B(x,y) And G(x,y) represent the intensity of the red, green and blue channels for each pixel, respectively. We sort and select a certain percentage of the brightest pixels, then calculate their average Ac value for each RGB channel.

  1. Building an optimal transmission map:

building a transmission map

according to the formula t(x,y)=e^{-\beta*d(x,y)} where is the atmospheric attenuation coefficient, which optimally reflects the degree of light penetration through the fog at each point in the image. Although there is a simpler alternative t(x,y)=1-{\omega}*d(x,y) Where \omega amount of haze to remove

  1. Refining the transmission map:

Apply Guided Filter to the resulting transmission map to

to soften the edges of bright areas of the image. These could be light sources, places with a strong haze effect, or various reflective surfaces. For the GPU version I used the work of Kaiming He (kahe@microsoft.com) implementation in MATLAB http://research.microsoft.com/en-us/um/people/kahe/eccv10/guided-filter-code-v1.rar

  1. Image restoration:

produced according to the formula: J(x,y)=\frac{I(x,y)-A_c}{max(t(x,y),t_{min})}+A_c where I(x,y) is the value of a foggy pixel, J(x,y) is the value of a fog-free pixel.

To compare the image before processing

The use of such a simple method can significantly improve the quality of images and facilitate their subsequent analysis and processing.

Project link github

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *