%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%实验名称:综合性图像处理系统设计与开发
%%%%组员:曹旭,王鑫,谢思雨
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = test(varargin)
% TEST MATLAB code for test.fig
% TEST, by itself, creates a new TEST or raises the existing
% singleton*.
%
% H = TEST returns the handle to a new TEST or the handle to
% the existing singleton*.
%
% TEST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TEST.M with the given input arguments.
%
% TEST('Property','Value',...) creates a new TEST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before test_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to test_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 test
% Last Modified by GUIDE v2.5 03-Nov-2017 08:30:48
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @test_OpeningFcn, ...
'gui_OutputFcn', @test_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 test is made visible.
function test_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 test (see VARARGIN)
% Choose default command line output for test
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.axes1,'visible','off'); %消除初始化图表
set(handles.axes2,'visible','off');
set(handles.axes3,'visible','off');
set(handles.axes4,'visible','off');
set(handles.axes5,'visible','off');
set(handles.axes6,'visible','off');
% This sets up the initial plot - only do when we are invisible
% so window can get raised using test.
% if strcmp(get(hObject,'Visible'),'off')
% plot(rand(5));
% end
% UIWAIT makes test wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = test_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 updatebutton.
function updatebutton_Callback(hObject, eventdata, handles)
% hObject handle to updatebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I; %全局变量
global t;
global t2;
global t3;
global R1;
global G1;
global B1;
global S1;
global S2;
global S3;
popup_sel_index = get(handles.popupmenu, 'Value');
switch popup_sel_index
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 1 %锐化
cla ; %清除axes
I4=im2double(I);
I2=rgb2gray(I);
[m,n,c]=size(I4);
A=zeros(m,n);
C=zeros(m,n);
d=0;
for i=1:m
for j=1:n
C(i,j)=I4(i,j,1);
end
end
S=zeros(m-2,n-2);
sum=0;s=0;
for i=2:m-1
for j=2:n-1
S(i,j)=((C(i,j)-C(i-1,j-1))^2+(C(i,j)-C(i-1,j))^2+(C(i,j)-C(i-1,j+1))^2+(C(i,j)-C(i,j-1))^2+(C(i,j)-C(i,j+1))^2+(C(i,j)-C(i+1,j-1))^2+(C(i,j)-C(i+1,j))^2+(C(i,j)-C(i+1,j+1)))^2;
s=sqrt(S(i,j));
d=10;
A(i,j)=d*C(i-1,j)+d*C(i,j-1)+d*C(i+1,j)+d*C(i,j+1)-4*d*C(i,j);
end
end
axes(handles.axes1); %画图像
cla;
imshow(C);title('原图');
axes(handles.axes2);
cla;
B=C-A;
imshow(B);title('差分法锐化');
%1、 filter2、conv2将输入转换为double类型,输出也是double的,输入总是补零
%2、 imfilter:不将输入转换为double,输出只与输入同类型
H=fspecial('sobel'); %选择sobel算子
J=filter2(H,I2)/255; %卷积运算
axes(handles.axes4);
cla;
imshow(J);
title('sobel算子锐化');
h=[0 1 0,1 -4 1,0 1 0]; %自定义拉普拉斯算子
J1=conv2(I2,h,'same')/255; %卷积运算(矩阵,算子,'边界点卷积方式')
axes(handles.axes5);
cla;
imshow(J1);
title('拉普拉斯算子锐化');
%%%%%%消除%%%%%%
axes(handles.axes6);
cla reset; %清空axes
delete(get(gca,'children')) %消除所有子对象
delete(get(gca,'title')) %消除title
axis off; %消除axis坐标轴
axes(handles.axes3);
cla reset; %清空axes
delete(get(gca,'children')) %消除所有子对象
delete(get(gca,'title')) %消除title
axis off; %消除axis坐标轴
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 2 %图像平滑:中值滤波,均值滤波
cla;
% I=imread('bmp.bmp');
I6= rgb2gray(I); %灰度图
t2=str2num(get(handles.T2edit,'String'));
s2=num2str(t2);
J1=imnoise(I6,'salt & pepper',t2); %加均值为0,方差为0.02的椒盐噪声
J2=imnoise(I6,'gaussian',0,t2); %加均值为0,方差为0.02的高斯噪声。
axes(handles.axes1);
cla;
imshow(J1); %显示有椒盐噪声图像
title(strcat('加入方差',s2,'椒盐噪声')); % strcat连接
axes(handles.axes2);
cla;
imshow(J2); %显示有高斯噪声图像
title(strcat('加入方差',s2,'高斯噪声')); % strcat连接
t3=str2num(get(handles.filteredit,'String'));
I1= medfilt2(J1,[t3 t3]); %对有椒盐噪声图像进行3×3方形窗口中值滤波
I2= medfilt2(J2,[t3 t3]); %对有高斯噪声图像进行3×3方形窗口中值滤波
I3= filter2(fspecial('average',t3),J1)/255; %对于double型矩阵显示,必须除以255取0-1之间
I4= filter2(fspecial('average',t3),J2)/255; %也可保存在读取,自动变为8位图格式
s3=num2str(t3);
axes(handles.axes3);
cla;
imshow(I1); %显示有椒盐噪声图像的中值滤波结果
title(strcat(s3,'*',s3,'椒盐噪声中值滤波 '));
axes(handles.axes4);
cla;
imshow(I2); %显示有高斯噪声图像的中值滤波结果
title(strcat(s3,'*',s3,'高斯噪声中值滤波 '));
axes(handles.axes5);
cla;
imshow(I3);
title(strcat(s3,'*',s3,'椒�
评论0