数字图像处理课程设计
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
《数字视音频技术》
课程设计报告
题目:基于MATLAB/GUI数字图像处理专业名称:电子信息工程
班级:电信072 学号:
姓名:
2010年 12月20日
基于MATLAB/GUI数字图像处理
一.设计目标
图形用户界面(Graphical User Interface)简称GUI,在Matlab程序开发中起着举足轻重的作用,它有别于传统的VC、JAVA或者Delphi的界面开发方式。
作为一个数学运算能力很强的软件,Matlab的运算结果通常是用图形来表示的,GUI的使用更易于图形表现的多元化,在数字图像处理中更加的方便、直观。
下面设计一个简单的GUI数字图像处理,掌握GUI菜单,控件,回调函数的具体实现方法。
二.设计环境:
Windows xp
Matlab 7.1
三.方案论证
界面设计采用菜单模式,通过MATLAB图像处理工具箱提供的强大图像处理、图像设计功能来对图像进行处理。
通过做Matlab GUI界面来对图像进行编辑、缩放、加噪声、噪声滤波、颜色模型转换和图像的翻转。
通过对Matlab函数直接调用和自编函数来实现上述图像处理功能,其中图像进行任意角度翻转还用到了两个不同GUI之间数据传递实现的。
四.实验设计过程
1.菜单的创建和设置
菜单项的创建、设置可以通过系统函uimenu函数来完成,同时也可以利用GUI的设计工具来创建、设置。
如图1-1
图1-1 菜单栏的设置
2.控件的设计
现在,绝大多数的软件中,图形界面都包含有控件。
控件也是一种是图形对象通过使用各种类型的控件,可以建立起操作简便,功能强大的图形界面软件。
Matlab系统为我们提供了lO种控件对象如:复选框、可编辑文本框等。
实验的整体GUI界面设计如图2-1。
图2-1 GUI界面
3.实验运行过程与功能:
文件
运行界面如图4-1:
图4-1 运行界面
点击打开,打开一个图片,如图4-2
图 4-2 打开一个图片
编辑
点击编辑,双三次缩小,输入参数,如图4-3
图4-3
然后,选择旋转,界面如图4-4
图4-4图像旋转界面
输入一个角度,然后点击确定,就会把图片进行旋转,如45度,运行结果如图4-5
图4-5 图像旋转结果图
点下面任意一个的原色,然后点ok,就会对背景原色进行变换,比如选择bule,得到的结果图如图4-6
图4-6 原色转换结果图
图像处理
图4-7亮度处理
图4-8 Hsv 模型转化 图4-9图像腐蚀
图4-10高度滤波
五.结束语
由以上例子可以看出来,使用Matlab 来编写程序确实简洁、方便。
Matlab 系统本身提供了很多图像处理方面的很多方法,同时也有很多第三方提供的工具箱,这就大大的节省了我们的开发时间,缩短了开发的剧期。
由于Matlab 语言的语法简单、灵活,就使得使用Matlab 开发图像处理程序更简单,流程容易理解。
本实验在结合了老师教过的知识和自己理解的修改,在自己的努力
附录:
function varargout = image_proc(varargin)
% IMAGE_PROC M-file for image_proc.fig
% IMAGE_PROC, by itself, creates a new IMAGE_PROC or raises the existing % singleton*.
%
% H = IMAGE_PROC returns the handle to a new IMAGE_PROC or the handle to
% the existing singleton*.
%
% IMAGE_PROC('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in IMAGE_PROC.M with the given input arguments. %
% IMAGE_PROC('Property','Value',...) creates a new IMAGE_PROC or raises the
% existing singleton*. Starting from the left, property value pairs are % applied to the GUI before image_proc_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to image_proc_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 image_proc
% Last Modified by GUIDE v2.5 23-Dec-2010 12:50:50
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @image_proc_OpeningFcn, ...
'gui_OutputFcn', @image_proc_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 image_proc is made visible.
function image_proc_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 image_proc (see VARARGIN)
% Choose default command line output for image_proc
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes image_proc wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global img_path
global im
global choice
im=0;
img_path='';
choice=[1 1];
% --- Outputs from this function are returned to the command line. function varargout = image_proc_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 pushbutton2.
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)
global img_path;
global im;
global choice;
text={'Red Component','Green Component','Blue Component','Gray Image'};
if isempty(img_path)
msgbox('Select an image first or the image does not exist!');
else
if choice(1)==4
rgb2yuv(handles.axes2,im);
else
show_rgb(handles.axes2,im,choice(1));
end
set(handles.text3,'String',text{choice(1)});
end
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
% --- Executes on button press in pushbutton1.
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)
global img_path;
global im;
[filename, pathname] = uigetfile( {'*.bmp;*.jpg;*.png;*.jpeg;*.tif;*.gif', 'Image Files (*.bmp, *.jpg, *.png,*.jpeg,*.tif,*.gif)';'*.*', 'All Files (*.*)'}, 'Pick an image');
if isequal(filename,0) || isequal(pathname,0)
return;
end
cla;
axes(handles.axes1);
img_path=[pathname filename];
im=imread(img_path);
imshow(im);
set(handles.edit1,'string',img_path);
set(handles.text2,'visible','on');
set(handles.text3,'string','');
if (length(size(im))~=3)
set(handles.radiobutton1,'enable','off');
set(handles.radiobutton2,'enable','off');
set(handles.radiobutton3,'enable','off');
set(handles.radiobutton4,'enable','off');
set(handles.pushbutton2,'enable','off');
set(handles.uipanel2,'title','');
set(handles.popupmenu1,'enable','off');
else
set(handles.radiobutton1,'enable','on');
set(handles.radiobutton2,'enable','on');
set(handles.radiobutton3,'enable','on');
set(handles.radiobutton4,'enable','on');
set(handles.pushbutton2,'enable','on');
set(handles.uipanel2,'title','View of RGB componets');
set(handles.popupmenu1,'enable','on');
end
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
global choice;
choice(1)=1;
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton2
global choice;
choice(1)=2;
% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton3
global choice;
choice(1)=3;
% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton4
global choice;
choice(1)=4;
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
% --- Executes on button press in pushbutton3.
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)
global img_path;
global im;
if isempty(img_path)
msgbox('Select an image first or the image does not exist!');
else
model=0;
histFlag=get(handles.checkbox1,'Value');
if length(size(im)==3)
model=get(handles.popupmenu1,'Value');
end
[im_eq]=equalizations(im,model,histFlag);
axes(handles.axes2);
imshow(im_eq);
set(handles.text3,'string',' Equalized image');
end
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
% --- Executes on button press in pushbutton4.
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)
global im;
global im_path;
global flag;
flag=0;
[h,im1]=DCT_compression(handles.figure1,im);
if flag
axes(handles.axes2);
imshow(im1);
set(handles.text3,'string','DCT compression');
end
% -------------------------------------------------------------------- function fileopen_Callback(hObject, eventdata, handles)
% hObject handle to fileopen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global img_path;
global im;
[filename,pathname]=uigetfile({'*.bmp;*.jpg;*.png;*.jpeg;*.tif;*.gif',
'Image Files (*.bmp, *.jpg, *.png,*.jpeg,*.tif,*.gif)';'*.*', 'All Files (*.*)'},'载入图像');
if isequal(filename,0)|isequal(pathname,0)
errordlg('没有选中文件','警告');
return;
else
x=imread([pathname,filename]);
axes(handles.axes1);
imshow(x);
handles.img=x;
handles.noise_img=x;
guidata(hObject,handles)
end
cla;
axes(handles.axes1);
img_path=[pathname filename];
im=imread(img_path);
imshow(im);
set(handles.edit1,'string',img_path);
set(handles.text2,'Visible','on');
set(handles.text3,'string','');
if (length(size(im))~=3)
set(handles.radiobutton1,'enable','off');
set(handles.radiobutton2,'enable','off');
set(handles.radiobutton3,'enable','off');
set(handles.radiobutton4,'enable','off');
set(handles.pushbutton2,'enable','off');
set(handles.uipanel2,'title','');
set(handles.popupmenu1,'enable','off');
else
set(handles.radiobutton1,'enable','on');
set(handles.radiobutton2,'enable','on');
set(handles.radiobutton3,'enable','on');
set(handles.radiobutton4,'enable','on');
set(handles.pushbutton2,'enable','on');
set(handles.uipanel2,'title','View of RGB componets');
set(handles.popupmenu1,'enable','on');
end
% -------------------------------------------------------------------- function file_Callback(hObject, eventdata, handles)
% hObject handle to file (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% -------------------------------------------------------------------- function filesave_Callback(hObject, eventdata, handles)
% hObject handle to filesave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname] = uiputfile({'*.bmp;*.jpg;*.png;*.jpeg;*.tif;*.gif', 'Image Files (*.bmp, *.jpg, *.png,*.jpeg,*.tif,*.gif)';'*.*', 'All Files (*.*)'},'图片保存为');
if isequal([filename,pathname],[0,0])
errordlg('文件没有保存','警告');
return;
else
file=strcat(pathname,filename);
(handles.axes2);
i=getimage(gca);
imwrite(i,file);
end
% -------------------------------------------------------------------- function fileclose_Callback(hObject, eventdata, handles)
% hObject handle to fileclose (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(handles.figure1);
clc;
close all;
close(gcf);
% -------------------------------------------------------------------- function bianji_Callback(hObject, eventdata, handles)
% hObject handle to bianji (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% -------------------------------------------------------------------- function Untitled_6_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x0;
global x1;
global y0;
global y1;
global z0;
global z1;
global img_path;
global im;
x0=get(handles.edit4,'string');
y0=get(handles.edit5,'string');
z0=get(handles.edit6,'string');
x1=str2num(x0);
y1=str2num(y0);
z1=str2num(z0);
if (isempty(x0) || x1<1 || x1>256)
msgbox('0 < x <= 256 , please input right x!');
elseif isempty(y0) || y1<1 || y1>256
msgbox('0 < y <= 256 , please input right y!');
elseif isempty(z0) || z1 < x1 || z1 < y1
msgbox('倍数 >= x , 倍数 >= y , please input right 倍数!');
elseif x1==1 && y1==1 && z1 == 1 || x1==1 && y1==2 && z1 == 2 || x1==2 && y1==1 && z1 == 2
I=imread(img_path);
I_new=I;
axes(handles.axes2);
set(handles.text2,'string','放大后的图像');
imshow(I_new);
elseif z1-1>=x1 || z1-1>=y1
I=imread(img_path);
I_new=I(round(size(I,1)*x1/z1):round(size(I,1)*(x1+1)/z1),round(size(I,1 )*y1/z1):round(size(I,1)*(y1+1)/z1),1:end);
axes(handles.axes2);
set(handles.text2,'string','放大后的图像');
imshow(I_new);
else
I=imread(img_path);
I_new=I(round(size(I,1)*(x1-1)/z1):round(size(I,1)*x1/z1),round(size(I,1 )*(y1-1)/z1):round(size(I,1)*y1/z1),1:end);
axes(handles.axes2);
set(handles.text2,'string','放大后的图像');
imshow(I_new);
end
% -------------------------------------------------------------------- function Untitled_7_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global p1;
global y;
axes(handles.axes2);
prompt={'输入参数1:'};
defans={'60'};
p=inputdlg(prompt,'输入参数',1,defans);
p1=str2num(p{1});
y=imrotate(handles.img,p1);
imshow(y);
% -------------------------------------------------------------------- function liangdu_Callback(hObject, eventdata, handles)
% hObject handle to liangdu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt={'输入参数1','输入参数2','输入gamma'};
defans={'[0 0.8]','[0 1]','1'};
p=inputdlg(prompt,'输入参数',1,defans);
p1=str2num(p{1});
p2=str2num(p{2});
p3=str2num(p{3});
gamma=p3;
x=(handles.img);
y=imadjust(x,p1,p2,gamma);
axes(handles.axes2);
imshow(y);
% -------------------------------------------------------------------- function suoxiao_Callback(hObject, eventdata, handles)
% hObject handle to suoxiao (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes2);
prompt={'输入放大倍数:'};
defans={'0.5'};
p=inputdlg(prompt,'输入放大倍数',1,defans);
p1=str2num(p{1});
y=imresize(handles.img,p1,'bicubic');
imshow(y);
% -------------------------------------------------------------------- function zuozhuan_Callback(hObject, eventdata, handles)
% hObject handle to zuozhuan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes2);
x=(handles.img);
y=imrotate(x,90);
imshow(y);
% -------------------------------------------------------------------- function youzhuan_Callback(hObject, eventdata, handles)
% hObject handle to youzhuan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes2);
x=(handles.img);
y=imrotate(x,-90);
imshow(y);
% -------------------------------------------------------------------- function jiaodu_Callback(hObject, eventdata, handles)
% hObject handle to jiaodu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes2);
prompt={'输入参数1:'};
defans={'45'};
p=inputdlg(prompt,'输入参数',1,defans);
p1=str2num(p{1});
y=imrotate(handles.img,p1);
imshow(y);
% -------------------------------------------------------------------- function fushi_Callback(hObject, eventdata, handles)
% hObject handle to fushi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x;
global j;
global se;
global bw;
axes(handles.axes2);
x=(handles.img);
if isrgb(x)
msgbox('这是彩色图像,不能进行图像腐蚀','警告');
else
j=im2bw(x);
se=eye(5);
bw=bwmorph(j,'erode');
imshow(bw);
end
% -------------------------------------------------------------------- function hsv_Callback(hObject, eventdata, handles)
% hObject handle to hsv (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes2);
x=(handles.img);
if isrgb(x)
HSV=rgb2hsv(x);
imshow(HSV);
else
msgbox('这是灰度图像,不能转换','警告');
end
% -------------------------------------------------------------------- function gaodulvbo_Callback(hObject, ~, handles)
% hObject handle to gaodulvbo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
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
for j=1:N
d=sqrt((i-m)^2+(j-n)^2); % 计算高通滤波器传递函数
if d<=d0
h=0;
else h=1;
end
result(i,j)=h*g(i,j);
end
end
result=ifftshift(result);
y2=ifft2(result);
y3=uint8(real(y2));
imshow(y3);
end
% -------------------------------------------------------------------- function xuanzhuan_Callback(hObject, eventdata, handles)
% hObject handle to xuanzhuan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)。