当前位置:文档之家› 基于matlab的数字图像处理

基于matlab的数字图像处理

基于MATLAB数字图像处理题目MATLAB中集成了功能强大的图像处理工具箱,可以通过不同的算法对图像进行不同的处理,更加精确的对图像进行变换和更改,进一步提高了人们对图像处理的能力和认识。

通过用户自定义界面将简洁的界面与MATLAB程序结合起来,方便操作与应用。

1 功能介绍本程序是一个简单的图像处理程序,使用MATLAB软件编写完成。

主要具有灰度转换、亮度处理、显示频谱、左右翻转、上下翻转、向左旋转90度、向右旋转90度、任意角度旋转、保存等功能,并通过图形化交互界面(GUI)进行程序使用的交互。

交互界面如图1.图1 程序的交互界面2 功能实现程序由两个部分组成:MATLAB代码(.m文件)和GUI图形(.fig)。

程序使用的流程:图像输入—> 灰度转换(可选)—> 亮度处理(可选)—>显示频谱图(可选)—>左右翻转(可选)—>上下翻转(可选)—>向左旋转90度(可选)—>向右旋转90度(可选)—>任意角度旋转(可选)—>保存(可选)。

备注:软件版本:MATLAB R2010b2.1 获得图像文件图形获取的过程,下面是图像获取界面和获取后的效果图。

界面图效果图具体代码参见:function pushbutton1_Callback(hObject, eventdata, handles) 2.2 灰度转换过程主要包括对原图片灰度转换及显示。

通过灰度转换按钮,将源程序链接到图片。

具体程序如下:function pushbutton2_Callback(hObject, eventdata, handles) axes(handles.axes2);if isrgb(handles.img)y=rgb2gray(handles.img); %RGB••••••••••imshow(y);elsemsgbox('这已经是灰度图像','转换失败');end2.3 亮度处理过程在已获得图片的基础上,再进亮度处理的选择。

亮度提供输入选项如下:处理后结果:2.4 显示频谱图在已获得图像文件进行频谱变换,结果如下:具体代码参见:function pushbutton9_Callback(hObject, eventdata, handles) 2.5 左右翻转左右翻转图形:2.6 上下翻转上下翻转图形:具体代码参见:function pushbutton5_Callback(hObject, eventdata, handles) 2.7 向左旋转90度向左旋转90度图形:具体代码参见:function pushbutton6_Callback(hObject, eventdata, handles) 2.7 向右旋转90度向右旋转90度图形:具体代码参见:function pushbutton7_Callback(hObject, eventdata, handles) 2.7 任意角度旋转向左旋转30度图形:具体代码参见:function pushbutton8_Callback(hObject, eventdata, handles)2.7 保存保存修改过的图片,可以选择任一路径保存。

文件名自命:具体代码参见:function pushbutton14_Callback(hObject, eventdata, handles)3 程序总结本程序实现简单的图像处理功能及便捷的图形化交互界面。

具有以下特点与缺陷:1、程序简单明明了,易于查找各部分模块,进行编写更修改。

2、各部分程序均源于源于课本知识,比较容易理解与应用,程序涵盖各个变换模块。

3、可以对同一个目标图片进行变换,变换后均可以保存,方便存档,更具有人性化设计。

未尽功能:(1)、程序可进一步优化,可以实现更多不同功能,没有利用其它函数进行编译,导致程序功能不够强大。

(2)、亮度不可以用户调节,只可固定调节到某一个亮度。

(3)、图片处理不能包含更多格式的文件,这有待进一步提高。

(4)、程序运行需要打开.m文件和.fig文件,不够简单易操作。

4 课程总结简单的图像处理程序已于上面一一列举,在制作过程遇到过许多问题,比如图形的频谱变换,经过查找书上资料,通过fft变换即可以得到。

通过本次课程设计,使自己对MATLAB GUI设计流程有了比较深刻的体会,同时也了解了一般软件设计的过程。

在设计过程中碰到了很多的问题,通过这些问题,使自己分析问题,解决问题的能力得到了较大的提高。

在理工科的专业应用背景下,用matlab 进行相关计算与仿真编程的优势非常突出。

特定的问题处理算法,我们通常都以M文件的文本形式给定最终的解决方案,自己设计的程序是在MATLAB环境下,用MATLAB语言编写的,这对于有安装MATLAB软件的计算机上运行并不存在什么问题,关键是一般的计算机很少有去安装MATLAB软件的,那么要在这些机子上运行该程序要怎么办呢,难道要先安装MATLAB软件,这显然太麻烦了,对于一个通用的,比较成熟的解决方案,我们当然期望它能应用到更多的场合,而.exe (可执行)文件可运行于所有的通用WINDOWS操作系统,为此,将M文件转换成.exe 文件倒是个不错的想法。

附录(部分程序)function varargout = process(varargin)% PROCESS MATLAB code for process.fig% PROCESS, by itself, creates a new PROCESS or raises the existing% singleton*.%% H = PROCESS returns the handle to a new PROCESS or the handle to% the existing singleton*.%% PROCESS('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in PROCESS.M with the given input arguments.%% PROCESS('Property','Value',...) creates a new PROCESS or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before process_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to process_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 process% Last Modified by GUIDE v2.5 08-Dec-2014 23:30:51% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @process_OpeningFcn, ...'gui_OutputFcn', @process_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before process is made visible.function process_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 process (see VARARGIN)% Choose default command line output for processhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes process wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout = process_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 structurevarargout{1} = handles.output;% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)[name,path]=uigetfile({'*.bmp'},'载入图像');if isequal(name,0)|isequal(path,0)errordlg('没有选中文件','出错');return;elsex=imread([path,name]);axes(handles.axes1);imshow(x);handles.img=x;handles.noise_img=x;guidata(hObject,handles)end% 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)axes(handles.axes2);if isrgb(handles.img)y=rgb2gray(handles.img); %RGB••••••••••imshow(y);elsemsgbox('这已经是灰度图像','转换失败');end% 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)prompt={'输入参数1','输入参数2','输入gamma'};defans={'[0 0.7]','[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);% 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)% --- Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)axes(handles.axes2);if isrgb(handles.img)x=(handles.img);for k=1:3y(:,:,k)=fliplr(x(:,:,k));%左右翻转函数endimshow(y);elsex=(handles.img);y=fliplr(x);imshow(y);end% 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)% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)axes(handles.axes2);x=(handles.img);if isrgb(handles.img)for k=1:3y(:,:,k)=flipud(x(:,:,k));%上下翻转函数endimshow(y);elsex=(handles.img);y=flipud(x);imshow(y);end% hObject handle to pushbutton5 (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 pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)axes(handles.axes2);x=(handles.img);y=imrotate(x,90);imshow(y);% hObject handle to pushbutton6 (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 pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)axes(handles.axes2);x=(handles.img);y=imrotate(x,-90);imshow(y);% hObject handle to pushbutton7 (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 pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)axes(handles.axes2);prompt={'输入参数1:'};defans={'30'};p=(prompt,'输入参数',1,defans);p1=str2num(p{1});y=imrotate(handles.img,p1);imshow(y);% hObject handle to pushbutton8 (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 pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)axes(handles.axes2);x=(handles.img);if isrgb(x)m=fft2(x(:,:,1));y=fftshift(m);imshow(log(abs(y)),[]);elsem=fft2(x);y=fftshift(m);imshow(log(abs(y)),[]);end% hObject handle to pushbutton9 (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 pushbutton14.function pushbutton14_Callback(hObject, eventdata, handles) [filename,pathname] = uiputfile('*.bmp','图片保存为');if isequal([filename,pathname],[0,0])errordlg('没有保存','出错');return;elsefile=strcat(pathname,filename);(handles.axes2);i=getimage(gca);imwrite(i,file);end% hObject handle to pushbutton14 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)。

相关主题