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 27-Jun-2023 17:12:12
% 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
mainfc;
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;
mainfc;
% Update handles structure
guidata(hObject, handles);
% 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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.jpeg'},'选择图像');
if isequal(filename,0) | isequal(pathname,0)
disp('取消,重选');
else
disp(['选择 ', fullfile(pathname, filename)])
end
x=imread(filename);
axes(handles.axes1)
imshow(x)
title('原图')
handles.x=x
guidata(hObject, handles);
set(handles.text2,'string','图像选择完毕')
% 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)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
set(handles.text2,'string','梯度倒数加权平均平滑算法。。。')
pause(1)
tic
x=handles.x
I=x;
H=sqrt(double(I));%把数据类型转换成double,然后进行平方根变换
H=uint8(H);%sqrt函数不支持uint8类型,把数据类型转换成uint8类型
%对图象p1-03施加高斯噪声和椒盐噪声并实施梯度倒数加权平滑法(公式4.2.3、4.2.4、4.2,利用方差评价空域平滑的效果
a=imnoise(I,'salt & pepper');
axes(handles.axes2); imshow(a); title('椒盐噪声图');
a=double(a);
[dep,wide]=size(a);
new_image=ones(size(a));
r=0.5;
for i=2:dep-1
for j=2:wide-1
g=0;
for m=-1:1
for n=-1:1
if(a(i+m,j+n)-a(i,j)==0)
g(m+2,n+2)=0;
else
g(m+2,n+2)=1/abs(a(i+m,j+n)-a(i,j));
end
end
end
G=sum(sum(g));
for m=-1:1
for n=-1:1
w(m+2,n+2)=g(m+2,n+2)/G;
end
end
new_image(i,j)=a(i,j)*r+(1-r)*(w(-1+2,-1+2)*a(i-1,j-1)+w(-1+2,0+2)*a(i-1,j)+w(-1+2,1+2)*a(i-1,j+1)+w(0+2,-1+2)*a(i,j-1)+w(0+2,1+2)*a(i,j+1)+w(1+2,-1+2)*a(i+1,j-1)+w(1+2,0+2)*a(i+1,j)+w(1+2,1+2)*a(i+1,j+1));
end
end
for i=2:dep-1
new_image(i,1)=new_image(i,2);
new_image(i,wide)=new_image(i,wide-1);
end
new_image(1,:)=new_image(2,:);
new_image(dep,:)=new_image(dep-1,:);
axes(handles.axes3); imshow(x); title('最后梯度倒数加权平滑');
time=toc
set(handles.edit1,'string',time)
set(handles.text2,'string','梯度倒数加权平均平滑处理完毕')
% 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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
set(handles.text2,'string','最大均匀性平滑滤波开始,约需等待95s。。。')
pause(1)
tic
x=handles.x
%**********************最大均匀性平滑法滤波*************************%
im=x;
[m,n]=size(im);
noise_pic=imnoise(im,'salt & pepper',0.02);
axes(handles.axes2)
imshow(noise_pic);
title('椒盐噪声图')
I=im2double(im) ;
for h=1:m
X(1,h)=I(1,h);
X(2,h)=I(2,h);
X(n-1,h)=I(n-1,h);
X(n,h)=I(n,h);
end
for j=1:n
X(j,1)=I(j,1);
X(j,2)=I(j,2);
X(j,m-1)=I(j,m-1);
X(j,m)=I(j,m);
end
for i=3:n-2
for j=3:m-2
F1=[I(i-2,j-2),I(i-2,j-1),I(i-2,j),I(i-1,j-2),I(i-1,j-1),I(i-1,j),I(i,j-2),I(i,j-1),I(i,j)];%取出每个邻域的像素值
F2=[I(i-2,j+1),I(i-2,j-1),I(i-2,j),I(i-1,j+1),I(i-1,j-1),I(i-1,j),I(i,j+1),I(i,j-1),I(i,j)];
F3=[I(i-2,j+1),I(i-2,j+2),I(i-2,j),I(i-1,j+1),I(i-1,j+2),I(i-1,j),I(i,j+1),I(i,j+2),I(i,j)];
F4=[I(i+1,j-2),I(i+1,j-1),I(i+1,j),I(i-1,j-2),I(i-1,j-1),I(i-1,j),I(i,j-2),I(i,j-1),I(i,j)];
F5=[I(i+1,j+1),I(i+1,j-1),I(i+1,j),I(i-1,j+1),I(i-1,j-1),I(i-1,j),I(i,j+1),I(i,j-1),I(i,j)];
F6=[I(i+1,j+1),I(i+1,j+2),I(i+1,j),I(i-1,j+1),I(i-1,j+2),I(i-1,j),I(i,j+1),I(i,j+2),I(i,j)];
F7=[I(i+1,j-2),I(i+1,j-1),I(i+1,j),I(i+2,j-2),I(i+2,j-1),I(i+2,j),I(i,j-2),I(i,j-1),I(i,j)];
F8=[I(i+1,j+1),I(i+1,j-1),I(i+1,j),I(i+2,j+1),I(i+2,j-1),I(i+2,j),I(i,j+1),I(i,j-1),I(i,j)];
F9=[I(i+1,j+1),I(i+1,j+2),I(i+1,j),I(i+2,j+1),I(i+2,j+2),I(i+2,j),I(i,j+1),I(i,j+2),I(i,j)];
I1=var(F1);
I2=var(F2);
I3=var(F3);
I4=var(F4);
I5=var(F5);
I6=var(F6);
I7=var(F7);
I8=var(F8);
I9=var(F9); %求方差
array=[I1,I2,I3,I4,I5,I6,I7,I8,I9]; %将方差放在一个数组中
A=sort(array); %对方差排序
switch A(1) %判断最小方差属于哪一个邻域
case I1
average=(I(i-2,j-2)+I(i-2,j-1)+I(i-2,j)+I(i-1,j-2)+I(i-1,j-1)+I(i-1,j)+I(i,j-2)+I(i,j-1)+I(i,j))/9;
case I2
average=(I(i-2,j+1)+I(i-2,j-1)+I(i-2,j)+I(i-1,j+1)+I(i-1,j-1)+I(i-1,j)+I(i,j+1)+I(i,j-1)+I(i,j))/9;
case I3
average=(I(i-2,j+1)+I(i-2,j+2)+I(i-2,j)+I(i-1,j+1)+I(i-1,j+2)+I(i-1,j)+I(i,j+1)+I(i,j+2)+I(i,j))/9;
case I4
average=(I(i+1,j-2)+I(i+1,j-1)+I(i+1,j)+I(i-1,j-2)+I(i-1,j-1)+I(i-1,j)+I(i,j-2)+I(i,j-1)+I(i,j))/9;
c
薰衣草之夏龙
- 粉丝: 930
- 资源: 68
最新资源
- yolo算法-麻将数据集-2205张图像带标签-绿色-北-南方-西-白色-万-东-红色.zip
- 基于Python卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计毕业源码案例设计
- 公开整理-农业科技创新数据集(2010-2022).xlsx
- WordPress在线社交问答社区主题Discy V3.8.1
- yolo算法-动物数据集-8944张图像带标签-自行车-背景-大象-豹-牛-熊-鹿-马-摩托车-猎豹-福克斯-猴子-美洲虎-太阳能电池板-老虎-犀牛-狮子-山羊-人-狗-天鱼-鸟.zip
- yolo算法-猴子-大象-猪动物数据集-6229张图像带标签-猴子-大象-猪-牛-鹿-熊-棕熊-老虎.zip
- yolo算法-道路损伤检测数据集-17145张图像带标签-纵向的-坑洼.zip
- 1MPS公司文档.zip
- WordPress主题 多本小说阅读模板
- yolo算法-手套-无手套-人数据集-14163张图像带标签-手套-无手套.zip
- 省级金融业增加值数据集(2005-2022年)
- Video_1732514072178.mp4
- yolo算法-多类别动物数据集-8893张图像带标签-猴子-奶牛-大象-水牛-美洲虎-熊-鹿-马-狗-老虎-鸟-狮子-猎豹-山羊.zip
- Go语言实现高质量代理池构建与部署
- yolo算法-动物类别数据集-21613张图像带标签-人-奶牛-鹰-大象-汽车-猪-水牛-熊-鹿-雨伞-狗-老虎-浣熊-狼.zip
- yolo算法-手套-无手套-人数据集-14773张图像带标签-手套-无手套-人-无头盔-无口罩-没有安全鞋-无护耳器-无背心-护耳器-背心-安全鞋-无玻璃-头盔-面具-玻璃杯.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈