De-illumination non-uniform MATLAB algorithm and code release

Source: Internet
Author: User
Tags square root

Other Original blog Http://blog.csdn.net/baolinq

Mainly see the third part of the can, the front is some other common basic image methods. Adaptive correction algorithm of illumination nonuniformity image based on two-dimensional gamma function

In the process of video and image acquisition, due to the complexity of objects, the interaction between objects and the changeable environment lighting conditions, often lead to uneven illumination of the scene, mainly manifested in the bright area of the image light enough or too strong, and dark area illumination is insufficient, Cause some important details of the information can not be highlighted or even obscured, seriously affect the image of visual effects and application value, so to carry out the calibration of uneven illumination image, to eliminate the influence of uneven illumination on the image, has become a research hotspot in the field of image processing.

Recently in the detection of some objects, some of the original image of the light is very uneven, affecting the detection accuracy. Uneven illumination of the image for target detection is actually quite large, I was thinking about whether to start from the source image, improve or improve the quality of the image, thereby improving the detection accuracy. But this seems to be a bit problematic, in this case, should not be in the deep learning sample data to increase the uneven illumination of the image, so that the test image can be successfully detected. First of all, this article just talk about how to light uneven, so as to improve the image quality.

This article is mainly for similar above type image, the illumination is uneven, some places the brightness is larger some is very dark.

Tried a lot of ways:

1. Histogram equalization

The "central idea" of histogram equalization is to change the gray histogram of the original image from a certain gray area in the comparative concentration to the uniform distribution in the whole gray range. The idea is very simple, first of all the gray level distribution of the original image, get the cumulative distribution function, the function can be obtained from the original map and the result map of the mapping relationship f, for each pixel function this mapping.

This can increase the contrast of the image. Here is a screenshot of the experimental results:

Traditional algorithm test results

Analysis: From top to bottom respectively: original, grayscale, histogram equalization after the graph, the corresponding test results are respectively.

It can be seen that the image after the histogram equalization process is detected by two car, and the original picture is not detected. Although the histogram equalization, the original image light intensity of the place is exposed very serious, (human eye visual) processing results are not good, but the experiment showed more conducive to target detection.

Overall, there is a certain improvement effect but not good enough, or there is no detection of cars.

2.retenix de-Fog algorithm

Retinex theory has a good effect on color image enhancement, image de-fog, non-uniformity of illumination and color image restoration. There are many blog posts on the Internet that this algorithm, is a very classic algorithm, test results screenshot:

Original:

Retinex Effect Diagram

Analysis: From the visual effect of human eyes, Retinex treatment to light effect is better, but the test results are not improved.


3. Adaptive correction algorithm for illumination uneven image based on two-dimensional gamma function

Based on the two-dimensional gamma function illumination uneven image adaptive correction algorithm, the idea of the algorithm in the literature is relatively simple, the realization of the paper is not so good effect:

(1) Using multi-scale Gaussian function to remove the illumination component of the scene

(2) then a two-dimensional gamma function is constructed, and the parameters of the two-dimensional gamma function are adjusted by the distribution characteristics of the illumination component, the luminance value of the illumination over-strong region is reduced, the luminance value of the illumination over-dark area is improved, and the adaptive correction processing of the illumination image is realized finally.

The light component can be obtained by using the Gaussian function and the source image for convolution. G is the Gaussian function, F is the source image, and I is the illumination component.


The two-dimensional gamma function O (x, y), F is the source image, and gamma is the exponential value of the luminance enhancement, determined by the luminance mean value of the illumination component and the illumination component.


To prevent the RGB channel from interacting with each other, the entire process is performed in the HSV color space, where the luminance component V is processed and then converted from the HSV space to the RGB space.

Note: There is a problem with the formula for the original paper here, it should be the author's clerical error, and the gamma Index should be m-i (x, y) instead of I (x, y)-M. Otherwise the results are not correct. Simple analysis:

Base is less than 1, the smaller the index, the greater the result, and the larger the index, the smaller the result. Gamma is also a power exponent with a base of less than 1.

For example analysis: According to the wording of the paper, set M=128,i (x, y) is a darker place gray to 64,γ is, is greater than 1, the base is less than 1, then the result is less than the base, dark place gray to smaller

If I (x, y) is brighter where the gray level is 192,γ is the square root 0.5, is less than 1, the base is less than 1, then the result is greater than the base. The brightness of the local gray scale becomes larger

The result is that the dark areas become darker, the brighter places become brighter, and obviously not.

The index of gamma should be m-i (x, y), so the formula in the paper is to deduce it yourself ~ ~

The algorithm flow diagram is as follows:

According to this algorithm flowchart, we write the corresponding MATLAB code.

RGB2HSV, for H-component multi-scale Gaussian convolution (Gaussian filtering), two-dimensional gamma function correction, HSV2RGB, end.

Clc,close all;
TIC;
Im=imread (' 1128-2.jpg ');
Figure;
Imshow (IM);
Title (' original image ');
[H,S,V]=RGB2HSV (IM);    % go to HSV space, to brightness h processing
% Gaussian filter
hsize= min (Size (im,1), size (im,2)),% Gaussian convolution core size
q=sqrt (2);
C sigma2=80 in sigma1=15;% paper
;
sigma3=250;
F1 = fspecial (' Gaussian ', hsize,sigma1/q);
F2 = fspecial (' Gaussian ', hsize,sigma2/q);
F3 = fspecial (' Gaussian ', hsize,sigma3/q);
Gaus1= IMFilter (V, F1, ' replicate ');
Gaus2= IMFilter (V, F2, ' replicate ');
gaus3= IMFilter (V, F3, ' replicate ');
gaus= (GAUS1+GAUS2+GAUS3)/3;    % multi-scale Gaussian convolution, weighted, weight of 1/3
% gaus= (gaus*255);
Figure;
Imshow (gaus,[]);
Title (' Illumination Component ');
% two-dimensional gamma convolution
m=mean (Gaus (:));
[W,height]=size (v);
Out=zeros (Size (v));
Gama=power (0.5, ((M-gaus)/m));% according to the formula Gamma correction processing, the paper formula is wrong
out= (Power (V,gama));
Figure;
Imshow (out,[]);
Rgb=hsv2rgb (h,s,out);   % back to RGB space display figure
;
Imshow (RGB);
Title (' Processing result ')
TOC;


Attention:

The paper does not say how big the convolution core, but according to the degree of fuzzy extraction of light components, convolution core should be taken very large, I here is to take the image and high school of the smaller, Min (h,w);

Practice has found that the use of imfilter in Gaussian convolution

The function is much faster than the CONV2 function, in the test, the same image, using the IMFilter

The entire process of the function is within 1s, while using the CONV2 function takes more than 10 seconds.

Experimental test:


Above is the screenshot of the paper processing effect, the following is my test screenshot, the effect is still possible, in turn, the original image, lighting components, effect diagram



Error processing result, dark place change dark, bright place change bright




Reference documents

[1] zhi, Wang Dianwei, Liu Ying, et. Adaptive correction algorithm for illumination Nonuniform image based on two-dimensional gamma function [J]. Journal of Beijing Polytechnic University, 2016, 36 (2): 191-196.


OK, the end of this article, the next one see, there are questions welcome to discuss the discussion below ~ ~ ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.