【图像增强】基于暗通道实现图像去雾matlab源码含GUI
一、简介边缘是图像的最重要的特征。边缘是指周围像素灰度有阶跃变化或屋顶变化的那些像素的集合。边缘检测主要是灰度变化的度量、检测和定位。有很多种不同的边缘检测方法同一种方法使用的滤波器也不尽相同。图像边缘检测就是研究更好的边缘检测方法和检测算子。边缘检测的基本思想\ (1)利用边缘增强算子突出图像中的局部边缘\ (2)然后定义像素的“边缘强度”通过设置阈值的方法提取边缘点集。由于噪声和模糊的存在监测到的边界可能会变宽或在某点处发生间断。\ 边界检测包括两个基本内容\ i. 用边缘算子提取出反映灰度变化的边缘点集\ ii. 在边缘点集合中剔除某些边界点或填补边界间断点并将这些边缘连接成完整的线\ 常用的检测算子有拉普拉斯边缘检测算法、Robert边缘检测算子、Sobel边缘检测算子、Prewitt边缘检测算子、Canny边缘检测算子。二、源代码 function varargout DIPGUI(varargin) % DIPGUI MATLAB code for DIPGUI.fig % DIPGUI, by itself, creates a new DIPGUI or raises the existing % singleton. % % H DIPGUI returns the handle to a new DIPGUI or the handle to % the existing singleton. % % DIPGUI(CALLBACK,hObject,eventData,handles,...) calls the local % function named CALLBACK in DIPGUI.M with the given input arguments. % % DIPGUI(Property,Value,...) creates a new DIPGUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before DIPGUIOpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to DIPGUIOpeningFcn via varargin. % % *See GUI Options on GUIDEs 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 DIPGUI% Last Modified by GUIDE v2.5 30-Nov-2018 12:21:38% Begin initialization code - DO NOT EDIT guiSingleton 1; guiState struct(guiName, mfilename, ... guiSingleton, guiSingleton, ... guiOpeningFcn, DIPGUIOpeningFcn, ... guiOutputFcn, DIPGUIOutputFcn, ... guiLayoutFcn, [] , ... guiCallback, []); if nargin ischar(varargin{1}) guiState.gui_Callback str2func(varargin{1}); endif nargout [varargout{1:nargout}] guimainfcn(guiState, varargin{:}); else guimainfcn(guiState, varargin{:}); end % End initialization code - DO NOT EDIT% --- Executes just before DIPGUI is made visible. function DIPGUI_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 DIPGUI (see VARARGIN)% Choose default command line output for DIPGUI handles.output hObject;% Update handles structure guidata(hObject, handles);% UIWAIT makes DIPGUI wait for user response (see UIRESUME) % uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout DIPGUI_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 getpic. function getpic_Callback(hObject, eventdata, handles) % hObject handle to getpic (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global I [filename,pathname]... uigetfile({.;.bmp;.tif;*.png},select picture); %选择图片路径 str[pathname filename]; %合成路径文件名 Iimread(str); axes(handles.yuantu); %使用第一个axes imshow(I); %显示图片% --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % 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 savepic. function savepic_Callback(hObject, eventdata, handles) % hObject handle to savepic (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)[FileName,PathName] uiputfile({.jpg,JPEG(.jpg);... .bmp,Bitmap(.bmp);... .gif,GIF(.gif);... ., All Files (.)},... Save Picture,Untitled); if FileName0 return; else hgetframe(handles.chulihou); imwrite(h.cdata,[PathName,FileName]); end% --- Executes on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hint: get(hObject,Value) returns toggle state of radiobutton1% --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hint: get(hObject,Value) returns toggle state of radiobutton2% --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hint: get(hObject,Value) returns toggle state of radiobutton3% --- Executes on button press in radiobutton4. function radiobutton4_Callback(hObject, eventdata, handles) % hObject handle to radiobutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hint: get(hObject,Value) returns toggle state of radiobutton4% --- Executes on button press in radiobutton5. function radiobutton5_Callback(hObject, eventdata, handles) % hObject handle to radiobutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hint: get(hObject,Value) returns toggle state of radiobutton5% --- Executes during object creation, after setting all properties. function uibuttongroup2_CreateFcn(hObject, eventdata, handles) % hObject handle to uibuttongroup2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called% --- Executes when selected object is changed in uibuttongroup2. function uibuttongroup2_SelectionChangedFcn(hObject, eventdata, handles) % hObject handle to the selected object in uibuttongroup2 % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global Iglobal BW %定义全局变量strget(hObject,string); %拿到所选按钮的名称axes(handles.chulihou); %使用第二个axesswitch str %选择语句caseInitial %点击原图按钮 imshow(I); %显示原图 function imDst boxfilter(imSrc, r)% BOXFILTER O(1) time box filtering using cumulative sum % % - Definition imDst(x, y)sum(sum(imSrc(x-r:xr,y-r:yr))); % - Running time independent of r; % - Equivalent to the function: colfilt(imSrc, [2r1, 2r1], sliding, sum); % - But much faster.[hei, wid] size(imSrc); imDst zeros(size(imSrc));%cumulative sum over Y axis imCum cumsum(imSrc, 1); %difference over Y axis imDst(1:r1, :) imCum(1r:2r1, :); imDst(r2:hei-r, :) imCum(2r2:hei, :) - imCum(1:hei-2r-1, :); imDst(hei-r1:hei, :) repmat(imCum(hei, :), [r, 1]) - imCum(hei-2r:hei-r-1, :); 三、运行结果