基于MATLAB_GUI的数字图像处理程序设计课程设计 下载本文

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); 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);

---------------------------------------------------------

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)); 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

result=ifftshift(result); y2=ifft2(result); y3=uint8(real(y2));

imshow(y3); % 显示滤波处理后的图像 end

---------------------------------------------------------

function gaotong_Callback(hObject, eventdata, handles) %高通滤波器程序 axes(handles.axes2); x=(handles.img); if isrgb(x)

msgbox('这是彩色图像,不能通过高通滤波器','失败'); else

y1=imnoise(x,'gaussian'); %加高斯噪声 f=double(y1); % 数据类型转换 k=fft2(f); % 傅立叶变换 g=fftshift(k); % 转换数据矩阵 [M,N]=size(g); nn=2;

d0=3; %截止频率为3 m=fix(M/2); n=fix(N/2); for i=1:M