p1=str2num(p{1});
y=imresize(handles.img,p1,'bilinear'); %最近邻插值法放大
imshow(y);
------------------------------------------------
function
shuangsanci_Callback(hObject, eventdata, handles)
%双三次放大
axes(handles.axes2);
prompt={'输入放大倍数:'}; defans={'2'};
p=inputdlg(prompt,'输入放大倍数',1,defans);
p1=str2num(p{1});
y=imresize(handles.img,p1,'bicubic');
imshow(y);
-------------------------------------------------------
function
suoxiao_Callback(hObject, eventdata, handles)
%邻近插值缩小
axes(handles.axes2);
prompt={'输入放大倍数:'}; defans={'0.2'};
p=inputdlg(prompt,'输入放大倍数',1,defans);
p1=str2num(p{1});
y=imresize(handles.img,p1,
'nearest'); %最近邻插值法缩小
imshow(y);
------------------------------------------------------
function
shuangxian_Callback(hObject, eventdata, handles)
%双线性缩小
axes(handles.axes2);
13
prompt={'输入放大倍数:'}; defans={'0.2'};
p=inputdlg(prompt,'输入放大倍数',1,defans);
p1=str2num(p{1});
y=imresize(handles.img,p1,'bilinear'); %最近邻插值法缩小
imshow(y);
--------------------------------------------------------
function
shuangsancisuox_Callback(hObject, eventdata, handles)
%双三次缩小
axes(handles.axes2);
prompt={'输入放大倍数:'}; defans={'0.2'};
p=inputdlg(prompt,'输入放大倍数',1,defans);
p1=str2num(p{1});
y=imresize(handles.img,p1,'bicubic');
imshow(y);
------------------------------------------------------
function
xuanzhuan_Callback(hObject, eventdata, handles)
-------------------------------------------------------
function
updown_Callback(hObject, eventdata, handles)
%上下翻转
axes(handles.axes2); x=(handles.img);
if isrgb(handles.img) for k=1:3
y(:,:,k)=flipud(x(:,:,k));%上下翻转函数
end
imshow(y); else
x=(handles.img); y=flipud(x); imshow(y); end
---------------------------------------------------------
function
leftright_Callback(hObject, eventdata, handles)
%左右翻转
axes(handles.axes2); if isrgb(handles.img) x=(handles.img); for k=1:3
y(:,:,k)=fliplr(x(:,:,k));%左右翻转函数
end
imshow(y); else
x=(handles.img); y=fliplr(x); imshow(y); end
------------------------------------------------------
function
zeft90_Callback(hObject, eventdata, handles)
%左转90度
axes(handles.axes2); x=(handles.img);
y=imrotate(x,90); imshow(y);
-------------------------------------------------------
function
right90_Callback(hObject, eventdata, handles)
%右转90度
axes(handles.axes2); x=(handles.img);
y=imrotate(x,-90); imshow(y);
----------------------------
--------------------------
function
other_Callback(hObject, eventdata, handles)
%任意角度旋转
axes(handles.axes2); prompt={'输入参数1:'}; defans={'30'};
p=inputdlg(prompt,'输入参数',1,defans);
p1=str2num(p{1});
y=imrotate(handles.img,p1); imshow(y);
-----------------------------------------------------
function gs_Callback(hObject, eventdata, handles)
%加入高斯噪声
axes(handles.axes2);
prompt={'输入参数1:','输入参数2'};
defans={'0','0.02'};
p=inputdlg(prompt,'输入参数',1,defans);
p1=str2num(p{1});
p2=str2num(p{2}); y=imnoise(handles.img,'gaussian',p1,p2); imshow(y);
handles.noise_img=y; guidata(hObject,handles); -------------------------------------------------------
function jy_Callback(hObject, eventdata, handles)
%加入椒盐噪声
prompt={'输入参数1:'}; %对话框的设置,用户输入的是字符串
defans={'0.02'}; %缺省值 p=inputdlg(prompt,'输入参数',1,defans);
p1=str2num(p{1}); %字符串转化为数值
axes(handles.axes2);
14
x=(handles.img); y=imnoise(x,'salt & pepper',p1);
imshow(y);
handles.noise_img=y;
guidata(hObject,handles); --------------------------------------------------------
function cx_Callback(hObject, eventdata, handles)
%加入乘性噪声
axes(handles.axes2); prompt={'输入参数1:'}; defans={'0.02'};
p=inputdlg(prompt,'输入参数',1,defans);
p1=str2num(p{1});
y=imnoise(handles.img,'speckle',p1);
imshow(y);
handles.noise_img=y;
guidata(hObject,handles); -----------------------------------------------------
function
zhifangtutongji_Callback(hObject, eventdata, handles)
---------------------------------------------------------
function red_Callback(hObject, eventdata, handles)
%R直方图
set(handles.axes2,'HandleVisibility','ON');
axes(handles.axes2);
x=imhist(handles.img(:,:,1)); %直方图统计
x1=x(1:10:256); horz=1:10:256; bar(horz,x1);
set(handles.axes2,'xtick',0:50:255);
----------------------------
15
-----------------------------
function
gray_Callback(hObject, eventdata, handles)
%G直方图
set(handles.axes2,'HandleVisibility','ON');
axes(handles.axes2); if isrgb(handles.img)
x=imhist(handles.img(:,:,2)); %直方图统计
x1=x(1:10:256); horz=1:10:256; bar(horz,x1);
set(handles.axes2,'xtick',0:50:255);
else
msgbox('这是灰度图像','旋转失败');
end
------------------------------------------------------
function
blue_Callback(hObject, eventdata, handles)
%B直方图
set(handles.axes2,'HandleVisibility','ON');
axes(handles.axes2); if isrgb(handles.img)
x=imhist(handles.img(:,:,3)); %直方图统计
x1=x(1:10:256); horz=1:10:256; bar(horz,x1);
%axis([0 255 0 150000]); set(handles.axes2,'xtick',0:50:255);
%set(handles.axes2,'ytick',0:2000:15000);
else
msgbox('这是灰度图像','旋转失败');
end
---------------------------------------------------------
function
junheng_Callback(hObject, eventdata, handles)
%直方图均衡
set(handles.axes2,'HandleVisibility','ON');
axes(handles.axes2); if isrgb(handles.img)
a=histeq(handles.img(:,:,1));
b=histeq(handles.img(:,:,2));
c=histeq(handles.img(:,:,3));
k(:,:,1)=a; k(:,:,2)=b; k(:,:,3)=c; imshow(k); else
h=histeq(handles.img); %直方图均衡
imshow(h); end
--------------------------------------------------------
%频谱分析
-----------------------------------------------------
function
pinpu_Callback(hObject, eventdata, handles)
--------------------------------------------------------
function
pinputu_Callback(hObject, eventdata, handles)
%显示频谱图
axes(handles.axes2); x=(handles.img); if isrgb(x)
m=fft2(x(:,:,1));
16
y=fftshift(m);
imshow(log(abs(y)),[]); else
m=fft2(x);
y=fftshift(m);
imshow(log(abs(y)),[]); end
--------------------------------------------------------
function
frequency_Callback(hObject, eventdata, handles)
%低通滤波器
axes(handles.axes2); x=(handles.img); if isrgb(x)
msgbox('这是彩色图像,不能通过低通滤波器','失败');
else
y1=imnoise(x,'salt & pepper'); % 叠加椒盐噪声
f=double(y1); % 数据类型转换,MATLAB不支持图像的无符号整型的计算
g=fft2(f); % 傅立叶变换
g=fftshift(g); % 转换数据矩阵
[M,N]=size(g);
nn=2; % 二阶巴特沃斯(Butterworth)低通滤波器
d0=10; %截止频率为10 m=fix(M/2); n=fix(N/2); for i=1:M
for j=1:N
d=sqrt((i-m)^2+(j-n)^2);
h=1/(1+0.414*(d/d0)^(2*nn)); % 计算低通滤波器传递函数
result(i,j)=h*g(i,j);
end end
相关推荐: