嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 5 元微信扫码支付:5 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
MATLAB图像处理及GUI设计
图像滤波去噪
亮度调节
对比度调节
饱和度调节
HSI域的变化
function varargout = myHSI(varargin)
% MYHSI MATLAB code for myHSI.fig
% MYHSI, by itself, creates a new MYHSI or raises the existing
% singleton*.
%
% H = MYHSI returns the handle to a new MYHSI or the handle to
% the existing singleton*.
%
% MYHSI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYHSI.M with the given input arguments.
%
% MYHSI('Property','Value',...) creates a new MYHSI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before myHSI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to myHSI_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 myHSI
% Last Modified by GUIDE v2.5 04-Aug-2020 13:01:39
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @myHSI_OpeningFcn, ...
'gui_OutputFcn', @myHSI_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 myHSI is made visible.
function myHSI_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 myHSI (see VARARGIN)
% Choose default command line output for myHSI
handles.output = hObject;
axes(handles.axes1);
set(gca, 'vis', 'off')
axes(handles.axes2);
set(gca, 'vis', 'off')
axes(handles.axes3);
set(gca, 'vis', 'off')
axes(handles.axes4);
set(gca, 'vis', 'off')
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes myHSI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = myHSI_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 pushbutton1_Callback(hObject, eventdata, handles)
% 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)
filter = { ...
'*.bmp;*.jpg;*.gif;*.emf', '所有图像文件 (*.bmp; *.jpg; *.gif; *emf)'; ...
'*.bmp', '位图文件 (*.bmp)'; ...
'*.jpg', 'JPEG文件 (*.jpg)'; ...
'*.gif', 'GIF文件 (*.gif)'; ...
'*.emf', '图元文件 (*.emf)'; ...
'*.*', '所有文件 (*.*)' ...
};
% 选择文件
[filename, pathname] = uigetfile( filter, '打开...');
if isequal(filename,0) | isequal(pathname,0), return, end
% 读入图像并显示
[X, map] = imread([pathname filename]);
% colormap(map)
% image(X)
axes(handles.axes1); cla reset;
imshow(X);title('原图');
% 设置坐标系为适合显示图像的方式
% axis image
set(gca, 'vis', 'off')
handles.I=X;
guidata(hObject, handles);
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 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)
I=handles.I;
a=str2num(get(handles.edit1,'string'))
% 平滑滤波-高斯滤波
W = fspecial('gaussian',[a,a],1);
I = imfilter(I, W, 'replicate');
axes(handles.axes2); cla reset;
imshow(I);title('高斯滤波后图像');
% --- 祛斑操作
function pushbutton3_Callback(hObject, eventdata, handles)
% 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)
I=handles.I;
n =7; % 窗口大小
[ height, width ] = size(I);
x1 = double(I);
x2 = x1;
for i = 1: height-n 1
for j = 1:width-n 1
mb = x1( i:(i n-1), j:(j n-1) );%获取图像中n*n的矩阵
mb = mb(:); %将mb变成向量化,变成一个列向量
mm = median(mb); %取中间值
x2( i (n-1)/2, j (n-1)/2 ) = mm;
end
end
I = uint8(x2);
axes(handles.axes2); cla reset;
imshow(I);title('中值滤波后(去斑)');
% --- 亮度调节
function slider3_Callback(hObject, eventdata, handles)
% hObject handle to slider3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 0.02的步长
I=handles.I;
% -1:0.2:1 --> 0.1:10
v=get(handles.slider3,'value');
if v<0
m=1 v
end
if v>=0
m=v*10
end
axes(handles.axes2); cla reset;
I=rgb2hsi(I);
% figure;
% imshow(I);title('HSI域');
H1=I(:,:,1);
S1=I(:,:,2);
X1=I(:,:,3)*m; % 亮度调节
% 色度 饱和度 强度
I=cat(3,H1,S1,X1);
f1=hsi2rgb(I);
imshow(f1),title('HSI亮度调节');
% set(handles.text2,'string',num2str(ceil(100*v)));
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider3_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- 饱和度调节
function slider4_Callback(hObject, eventdata, handles)
% hObject handle to slider4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 0.02的步长
I=handles.I;
% -1:0.2:1 --> 0.1:10
v=get(handles.slider4,'value');
if v<0
m=1 v
end
if v>=0
m=v*10
end
axes(handles.axes2); cla reset;
I=rgb2hsi(I);
% figure;
% imshow(I);title('HSI域');
H1=I(:,:,1);
S1=I(:,:,2)*m;
X1=I(:,:,3); % 亮度调节
% 色度 饱和度 强度
I=cat(3,H1,S1,X1);
f1=hsi2rgb(I);
imshow(f1),title('HSI饱和度调节');
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider4_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% ---打开图像
function pushbutton4_Callback(hObject, eventdata, handles)
% 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)
filter = { ...
'*.bmp;*.jpg;*.gif;*.emf', '所有图像文件 (*.bmp; *.jpg; *.gif; *emf)'; ...
'*.bmp', '位图文件 (*.bmp)'; ...
'*.jpg', 'JPEG文件 (*.jpg)'; ...
'*.gif', 'GIF文件 (*.gif)'; ...
'*.emf', '图元文件 (*.emf)'; ...
'*.*', '所有文件 (*.*)' ...
};
% 选择文件
[filename, pathname] = uigetfile( filter, '打开...');
if isequal(filename,0) | isequal(pathname,0), return, end
% 读入图像并显示
[X, map] = imread([pathname filename]);
% colormap(map)
% image(X)
axes(handles.axes3); cla reset;
imshow(X);title('原图');
% 设置坐标系为适合显示图像的方式
% axis image
set(gca, 'vis', 'off')
handles.A=X;
guidata(hObject, handles);
% --- 打开图像.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton4.
function pushbutton4_ButtonDownFcn(hObject, eventdata, handles)
% 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)
% --- 对比度2
function slider5_Callback(hObject, eventdata, handles)
% hObject handle to slider5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.A;
% -1:0.2:1 --> 0.1:10
v=get(handles.slider5,'value')*50 50
axes(handles.axes4); cla reset;
img = ContrastAdjust(I,v);
imshow(img),title('对比度调节');
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider5_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- 饱和度2.
function slider6_Callback(hObject, eventdata, handles)
% hObject handle to slider6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.A;
% -1:0.2:1 --> 0.1:10
v=get(handles.slider6,'value');
if v<0
m=1 v
end
if v>=0
m=v*10
end
axes(handles.axes4); cla reset;
I=rgb2hsi(I);
% figure;
% imshow(I);title('HSI域');
H1=I(:,:,1);
S1=I(:,:,2)*m;
X1=I(:,:,3); % 亮度调节
% 色度 饱和度 强度
I=cat(3,H1,S1,X1);
f1=hsi2rgb(I);
imshow(f1),title('HSI饱和度调节');
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider6_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- 背景去噪
function pushbutton5_Callback(hObject, eventdata, handles)
% 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)
I=handles.A;
a=5;
% 平滑滤波-高斯滤波
W = fspecial('gaussian',[a,a],1);
I = imfilter(I, W, 'replicate');
axes(handles.axes4); cla reset;
imshow(I);title('背景去噪');
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% 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)
close;