[Matlab image enhancement] dark channel image defogging [including GUI source code 740]

1, Introduction

1 dark channel a priori image defogging method
1.1 light transmittance model
Due to the scattering of light in propagation, only part of the radiation emitted from the light source can reach the receiving sensor, and the others are scattered into the propagation medium. Assuming that the scattered light intensity is linear with the distance when the distance is small, when the light source is infinitely close to the sensor, the attenuation value of the light can be approximated as: Br, where β Is the scattering coefficient of air; r is the distance between the light source and the sensor. When the atmospheric density is uniform, the mathematical model of light transmittance is:

Where: D is the scene depth; t is the light transmittance, which is used to quantify the proportional relationship between the received light intensity of the sensor and the light intensity on the surface of the light source, that is, the proportional relationship between the non scattered radiation and the light source radiation.

1.2 dark channel prior theory
The dark channel prior theory based on statistics of a large number of clear images means that all pixels of most high-quality images without sky have at least one color channel in the three channels R, G and B. the gray value is quite low and even close to 0 [5], that is, the minimum radiation intensity value in a certain small area is very low. An image J can be defined as:

Where: J dark is the dark channel value of Image J; J is the gray value of channel c of Image J; Q(x) is a local micro region centered on pixel X; y is any pixel in the region.

1.3 dark channel a priori image defogging
The goal of image defogging is to restore the foggy image received by the sensor to a clear image by defogging using the useful information obtained. The dark channel prior image defogging process obtains the prior knowledge according to the dark channel principle, and then uses the foggy image degradation model to realize the image defogging effect.

1.3.1 image degradation model
In the field of computer vision graphics, the degradation model of foggy image is [6]:

Where: l(x) is the scene signal received by the sensor, that is, the input foggy image; Scene radiation J(x) is a clear image after signal processing; A is the ambient light intensity; t(x) is the atmospheric transmittance. J(x)t(x) is called direct attenuation term, which is used to quantify the signal loss in scene radiation and propagation. A(1-t(x)) represents the atmospheric scattered light intensity received by the image, which is the direct cause of color shift and cloud effect.

1.3.2 estimation of ambient light intensity
The higher the gray value in the dark channel image, the thicker the cloud, and the closer the gray value of] pixels in this part of the input image to the ambient light intensity. To estimate the ambient light intensity, first find the pixel with the highest gray value in the dark channel image and accounting for 01% of the total pixels of the image, record their corresponding coordinate index, then find the corresponding pixel in the input foggy image according to the coordinate index, and calculate the average gray value of the corresponding pixel in the foggy image as the ambient light intensity A.

1.3.3 estimation of atmospheric transmittance
t '(x) is used to represent the atmospheric transmittance in the filter window centered on pixel X. assuming that it is locally unchanged, the minimum values in the three color channels R, G and B are calculated respectively, i.e

By calculating the minimum values of the three color channels, the minimum gray value in the filter window centered on pixel x can be obtained, i.e

According to the a priori principle of dark channel and equation (2):

Therefore, the atmospheric transmittance calculated from equations (5) and (6) is:

1.3.4 defogging treatment
The dark channel prior condition can be used to quantify the cloud thickness and the radiation reduction of all pixels, and then restore A clear and high-quality image. Through the foggy image degradation model of equation (3), ambient light intensity A and atmospheric transmittance t(x), single image defogging can be carried out, i.e

2 Optimization of fog removal effect of dark channel a priori algorithm
The optimization process of this paper is shown in Figure 1. When the cloud and fog of the input image are uneven, the gray information of the atmospheric transmittance layer is only in a limited range, and the radiation reduction amount of the whole image will be limited to a certain range, which can not accurately restore the radiation intensity of the thick and thin areas of cloud and fog, thus affecting the image defogging effect, The method of stretching the contrast of atmospheric transmittance layer is considered to improve the fog free image quality based on the a priori of dark channel.

Fig. 1 optimization flow of image defogging processing effect based on dark channel a priori

2, Partial source code

unction varargout = zhongzhiquwu(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @zhongzhiquwu_OpeningFcn, ...
                   'gui_OutputFcn',  @zhongzhiquwu_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before zhongzhiquwu is made visible.
function zhongzhiquwu_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to zhongzhiquwu (see VARARGIN)
axes(handles.axes1);
imshow([255]);
axes(handles.axes2);
imshow([255]);
axes(handles.axes3);
imshow([255]);
axes(handles.axes4);
imshow([255]);
axes(handles.axes5);
imshow([255]);
% Choose default command line output for zhongzhiquwu
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes zhongzhiquwu wait for user response (see UIRESUME)
% uiwait(handles.figure1);
%

% --- Outputs from this function are returned to the command line.
function varargout = zhongzhiquwu_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global b
global dark_I2
global dark_I
global T
global J
axes(handles.axes1);
imshow([255]);
axes(handles.axes2);
imshow([255]);
axes(handles.axes3);
imshow([255]);
axes(handles.axes4);
imshow([255]);
axes(handles.axes5);
imshow([255]);
axes(handles.axes1)
[filename,pathname]=uigetfile({ ...
    '*.*','All Files(*.*)';},...
    'Select file');
%
if isequal([filename,pathname],[0,0])
    return
else
    %Read picture
    pic = fullfile(pathname,filename);
    b = imread(pic);
    imshow(b);%The above is the steps to open the picture. This sentence is to display the picture
   
    title('Original picture');
    [dark_I2,dark_I,T,J]=min_quwu(b);
    %handle.axes1=b;
end
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
global dark_I2
axes(handles.axes2);
imshow(dark_I2);
title('Estimated fog concentration');
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
global dark_I
axes(handles.axes3);
imshow(dark_I);
title('Correction of fog concentration by median filter');
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
global T
axes(handles.axes4);
imshow(T);
title('Perspective distribution');
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
global J
axes(handles.axes5);
imshow(J);
title('Defog image');
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
global dark_I2
axes(handles.axes2);
imshow(dark_I2);
title('Estimated concentration');
global dark_I
axes(handles.axes3);
imshow(dark_I);
title('Correction of fog concentration by median filter');
global T
axes(handles.axes4);
imshow(T);
title('Perspective distribution');
global J
axes(handles.axes5);
imshow(J);
title('Defog image');
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

3, Operation results

4, matlab version and references

1 matlab version
2014a

2 references
[1] Cai Limei MATLAB image processing -- theory, algorithm and example analysis [M] Tsinghua University Press, 2020
[2] Yang Dan, Zhao Haibin, long Zhe Detailed explanation of MATLAB image processing example [M] Tsinghua University Press, 2013
[3] Zhou pin MATLAB image processing and graphical user interface design [M] Tsinghua University Press, 2013
[4] Liu Chenglong Proficient in MATLAB image processing [M] Tsinghua University Press, 2015

5, Get code method

Matlab King assistant CSDN business card

Keywords: MATLAB AI Computer Vision

Added by cptnwinky on Fri, 07 Jan 2022 11:48:06 +0200