【图像去雾】直方图均衡化+Retinex理论图像去雾(带面板)【含GUI Matlab源码 706期】

⛄一、图像增强及直方图均衡化简介

1 图像增强
图像增强是对图像的某些特征,如边缘、轮廓、对比度等进行强调或锐化,以便于显示、观察或进一步分析与处理。通过对图像的特定加工,将被处理的图像转化为对具体应用来说视觉质量和效果更“好”或更“有用”的图像。
图像增强是最基本最常用的图像处理技术,常用于其他图像处理的预处理阶段。
在这里插入图片描述
(1)高通平滑、低通锐化;平滑模糊、锐化突出图像细节
(2)滤波器还有带通、带阻等形式
(3)根据噪声(椒盐噪声、高斯噪声…)的不同,选用不同的滤波
(4)邻域有4-邻域、对角邻域、8-邻域,相对应的有邻接,即空间上相邻、像素灰度相似
(5)图像边缘处理:忽略不处理、补充、循环使用
(6)目前尚未图像处理大多基于灰度图像

2 直方图均衡化
直方图均衡化主要用于增强灰度值动态范围偏小的图像的对比度。该方法的基本思想是把原始图像的灰度统计直方图变换为均匀分布的形式,这样就增加了像素灰度值的动态范围,从而达到增强图像整体对比度的效果。数字图像是离散化的数值矩阵,其直方图可以被视为一个离散函数,它表示数字图像中每一灰度级与其出现概率间的统计关系。假设一幅数字图像f(x,y)的像素总数为N,ra表示第k个灰度级对应的灰度,nk表示灰度为r的像素个数即频数,用横坐标表示灰度级,用纵坐标表示频数,则直方图可定义为®=,其中,P(n)表示灰度ry出现的相对频数即概率。直方图在一定程度上能够反映数字图像的概貌性描述,包括图像的灰度范围、灰度分布、整幅图像的亮度均值和阴暗对比度等,并可以此为基础进行分析来得出对图像进一步处理的重要依据。直方图均衡化也叫作直方图均匀化,就是把给定图像的直方图分布变换成均匀分布的直方图,是一种较为常用的灰度增强算法(2。直方图均衡化概括起来
包括以下三个主要步骤。
(1)预处理。输入图像,计算该图像直方图。
(2)灰度变换表。根据输入图像的直方图计算灰度值变换表。
(3)查表变换。执行变换x’=H(x),表示对步骤1中得到的直方图使用步骤2得到的灰度值变换表进行查表变换操作,通过遍历整幅图像的每一个像元,将原始图像灰度值x放入变换表H(x)中,可得到变换后的新灰度值x’。
根据信息论的相关理论,我们可以知道图像经直方图均衡化后,将会包含更多的信息
量,进而能突出某些图像特征。假设图像具有n级灰度,其第i级灰度出现的概率为pi,
则该级灰度所含的信息量为:
在这里插入图片描述
整张图片的信息量为
在这里插入图片描述
信息论已经证明,具有均匀分布直方图的图像,其信息量H最大。即当
Po=Pi=…=pn-i=1/n时,(1.2)式有最大值。

2.1 全局直方图处理
全局直方图处理通过对RGB图像的R、G、B三层通道分别进行直方图均衡化, 再整合到新的图像的方式来进行。一般来说,全局直方图去雾算法可以实现含雾图像的增强效果,处理前后的直方图在分布上具有明显变化,但在图像整体上容易出现某些色彩失真的现象。

2.2 局部直方图处理
全局直方图均衡化增强只是将原图像的直方图进行了均衡化,未能有效保持原始图像的局部特征,容易出现色彩失真问题。通过选择固定尺寸的滑动窗口作用于原始图像来进行局部直方图处理,可以在一定程度上保持原始图像的局部特征,提高图像增强的效果。因此, 局部直方图处理通过对RGB图像的R、G、B三层通道分别进行局部直方图均衡化,再整合到新的图像的方式来进行。

2.3 Retinex增强处理
基于全局直方图、局部直方图的图像去雾算法在理论及实现上比较简单,能起到一定的去雾处理效果。为了进行对比, 实验中采取了Retin ex图像增强算法来进行对比, 该算法可以平衡图像灰度动态范围压缩、图像增强和图像颜色恒常三个指标,能够实现对含雾图像的自适应性增强。因此, Retin ex增强处理通过对RGB图像的R、G、B三层通道分别应用Retin ex算法进行处理, 再整合到新的图像的方式来进行。

⛄二、部分源代码

function varargout = MainForm(varargin)
% MAINFORM MATLAB code for MainForm.fig
% MAINFORM, by itself, creates a new MAINFORM or raises the existing
% singleton*.
%
% H = MAINFORM returns the handle to a new MAINFORM or the handle to
% the existing singleton*.
%
% MAINFORM(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in MAINFORM.M with the given input arguments.
%
% MAINFORM(‘Property’,‘Value’,…) creates a new MAINFORM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MainForm_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MainForm_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE’s Tools menu. Choose “GUI allows only one
% instance to run (singleton)”.
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help MainForm

% Last Modified by GUIDE v2.5 5-Apr-2021 17:16:36

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @MainForm_OpeningFcn, …
‘gui_OutputFcn’, @MainForm_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 MainForm is made visible.
function MainForm_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 MainForm (see VARARGIN)

% Choose default command line output for MainForm
handles.output = hObject;
handles.Img1 = 0;%
handles.Img2 = 0;
% Update handles structure
guidata(hObject, handles);

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

% — Outputs from this function are returned to the command line.
function varargout = MainForm_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;

% --------------------------------------------------------------------
function File_Callback(hObject, eventdata, handles)
% hObject handle to File (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --------------------------------------------------------------------
function FileOpen_Callback(hObject, eventdata, handles)
% hObject handle to FileOpen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 打开
warning off all;
% 载入图像
[FileName,PathName,FilterIndex] = uigetfile({‘.jpg;.tif;.png;.gif’, …
‘所有图像文件’;…
.’,‘所有文件’ },‘载入图像’,…
‘.\images\sweden_input.jpg’);
if isequal(FileName, 0) || isequal(PathName, 0)
return;
end
InitFig(hObject, handles);
Img1 = imread(fullfile(PathName, FileName));
axes(handles.axes1);
imshow(Img1, []);
handles.Img1 = Img1;
handles.Img2 = 0;
guidata(hObject, handles);

% --------------------------------------------------------------------
function Exist_Callback(hObject, eventdata, handles)
% hObject handle to Exist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close();

% --------------------------------------------------------------------
function About_Callback(hObject, eventdata, handles)
% hObject handle to About (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msgbox(‘低对比度图像增强系统,全局及局部直方图均衡化和基于RETINEX理论图像对比度增强算法’, ‘提示信息’);

function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,‘String’) returns contents of edit1 as text
% str2double(get(hObject,‘String’)) returns contents of edit1 as a double

% — Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end

% --------------------------------------------------------------------
function ImageDeFog_Callback(hObject, eventdata, handles)
% hObject handle to ImageDeFog (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --------------------------------------------------------------------
function ColorSpaceDeFog_Callback(hObject, eventdata, handles)
% hObject handle to ColorSpaceDeFog (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --------------------------------------------------------------------
function RetinexDeFog_Callback(hObject, eventdata, handles)
% hObject handle to RetinexDeFog (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isequal(handles.Img1, 0)
msgbox(‘请载入图像!’, ‘提示信息’);
return;
end
Img2 = RemoveFogByRetinex(handles.Img1, 0);
axes(handles.axes2); imshow(Img2, []);
handles.Img2 = Img2;
guidata(hObject, handles);
set(handles.textInfo, ‘String’, …
‘基于RETINEX理论图像对比度增强算法。’);

% --------------------------------------------------------------------
function help_Callback(hObject, eventdata, handles)
% hObject handle to help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --------------------------------------------------------------------
function Flow_Callback(hObject, eventdata, handles)
% hObject handle to Flow (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str = ‘低对比度图像增强系统,首先载入图像并显示,然后选择对比度增强算法,最后可以观察直方图对比效果。’;
msgbox(str, ‘提示信息’);

% --------------------------------------------------------------------
function SaveGUI_Callback(hObject, eventdata, handles)
% hObject handle to SaveGUI (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 截图
SnapImage();

% --------------------------------------------------------------------
function SaveResult_Callback(hObject, eventdata, handles)
% hObject handle to SaveResult (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 保存
if isequal(handles.Img2, 0)
msgbox(‘请进行对比度增强处理!’, ‘提示信息’);
return;
end

⛄三、运行结果

【图像去雾】直方图均衡化+Retinex理论图像去雾(带面板)【含GUI Matlab源码 706期】_第1张图片
【图像去雾】直方图均衡化+Retinex理论图像去雾(带面板)【含GUI Matlab源码 706期】_第2张图片
【图像去雾】直方图均衡化+Retinex理论图像去雾(带面板)【含GUI Matlab源码 706期】_第3张图片

⛄四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1]黄丽韶.基于Retinex增强算法的图像去雾方法研究[J].无线互联科技. 2021,18(15)

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

你可能感兴趣的:(Matlab图像处理(进阶版),matlab,图像处理,计算机视觉)