matlab低照度降噪和增强gui代码
时间: 2023-11-02 10:11:38 浏览: 84
以下是一个基于 MATLAB GUI 的低照度图像降噪和增强代码示例:
```matlab
function varargout = LowLightEnhancement(varargin)
% LOWLIGHTENHANCEMENT MATLAB code for LowLightEnhancement.fig
% LOWLIGHTENHANCEMENT, by itself, creates a new LOWLIGHTENHANCEMENT or raises the existing
% singleton*.
%
% H = LOWLIGHTENHANCEMENT returns the handle to a new LOWLIGHTENHANCEMENT or the handle to
% the existing singleton*.
%
% LOWLIGHTENHANCEMENT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LOWLIGHTENHANCEMENT.M with the given input arguments.
%
% LOWLIGHTENHANCEMENT('Property','Value',...) creates a new LOWLIGHTENHANCEMENT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before LowLightEnhancement_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to LowLightEnhancement_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 LowLightEnhancement
% Last Modified by GUIDE v2.5 17-Aug-2021 19:56:48
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @LowLightEnhancement_OpeningFcn, ...
'gui_OutputFcn', @LowLightEnhancement_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 LowLightEnhancement is made visible.
function LowLightEnhancement_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 LowLightEnhancement (see VARARGIN)
% Choose default command line output for LowLightEnhancement
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes LowLightEnhancement wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = LowLightEnhancement_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 LoadImage.
function LoadImage_Callback(hObject, eventdata, handles)
% hObject handle to LoadImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.jpg';'*.png';'*.bmp';'*.tif';'*.gif'}, 'Choose an image file');
if isequal(filename,0) || isequal(pathname,0)
return;
else
image = imread(fullfile(pathname, filename));
axes(handles.OriginalImage);
imshow(image);
handles.image = image;
guidata(hObject,handles);
end
% --- Executes on button press in EnhanceImage.
function EnhanceImage_Callback(hObject, eventdata, handles)
% hObject handle to EnhanceImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get the original image
image = handles.image;
% Convert the image to grayscale
image = rgb2gray(image);
% Perform the low light enhancement using guided filter
image_enhanced = im2double(image);
image_enhanced = guidedfilter(image_enhanced, image_enhanced, 'radius', 32, 'epsilon', 0.01);
% Show the enhanced image
axes(handles.EnhancedImage);
imshow(image_enhanced);
% --- Executes on button press in SaveImage.
function SaveImage_Callback(hObject, eventdata, handles)
% hObject handle to SaveImage (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';'*.png';'*.bmp';'*.tif'}, 'Save the enhanced image', 'enhanced_image.jpg');
if isequal(filename,0) || isequal(pathname,0)
return;
else
% Get the enhanced image
image_enhanced = getimage(handles.EnhancedImage);
% Save the enhanced image
imwrite(image_enhanced, fullfile(pathname, filename));
end
```
该代码基于 MATLAB 的 GUI 工具箱,并使用 guided filter 对低照度图像进行降噪和增强。用户可以通过该 GUI 选择输入图像、进行处理和保存输出图像。
阅读全文