数字图像处理实验四、基于GUIDE的图像处理软件开发

发布时间:2019-08-15 09:41:50   来源:文档文库   
字号:

实验四基于GUIDE的图像处理软件开发

一、 实验目的

(1) 学习使用MATLAB GUIDE的基本操作。

(2) 以图像增强为例完成基本图像处理功能的回调函数编写。

二、 实验主要仪器设备

(1) 台式机或笔记本电脑。

(2) MATLAB软件(含GUIDE开发环境)。

三、 实验原理

(1) 基于灰度直方图变换的图像增强。

(2) 灰度修正图像增强。

(3) 图像平滑滤波。

(4) 图像锐化处理。

四、 实验内容

(1) 直方图的计算及用直方图均衡原理增强图像。

(2) 线性灰度变换图像增强。

(3) 对受椒盐噪声污染的图像采用低通处理模板去燥。

(4) 对受椒盐噪声污染的图像采用中值滤波去噪。

(5) 对图像采用梯度算子和拉普拉斯算子进行锐化。

五、 实验步骤

(1) 建立开发环境。

(2) 编写相关回调函数。

(3) 不断调试、优化,获得较满意的人机交互效果。

六、 实验程序

function varargout = test4(varargin)

% TEST4 MATLAB code for test4.fig

% TEST4, by itself, creates a new TEST4 or raises the existing

% singleton*.

%

% H = TEST4 returns the handle to a new TEST4 or the handle to

% the existing singleton*.

%

% TEST4('CALLBACK',hObject,eventData,handles,...) calls the local

% function named CALLBACK in TEST4.M with the given input arguments.

%

% TEST4('Property','Value',...) creates a new TEST4 or raises the

% existing singleton*. Starting from the left, property value pairs are

% applied to the GUI before test4_OpeningFcn gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to test4_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 test4

% Last Modified by GUIDE v2.5 30-May-2017 17:23:54

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @test4_OpeningFcn, ...

'gui_OutputFcn', @test4_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 test4 is made visible.

function test4_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 test4 (see VARARGIN)

% Choose default command line output for test4

handles.output = hObject;

I = ones(256,256);

axes(handles.axes1);imshow(I);

axes(handles.axes2);imshow(I);

axes(handles.axes3);imshow(I);

axes(handles.axes4);imshow(I);

axes(handles.axes5);imshow(I);

axes(handles.axes6);imshow(I);

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes test4 wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.

function varargout = test4_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 OpenFile.

function OpenFile_Callback(hObject, eventdata, handles)

[file path] = uigetfile('*.bmp;*.jpg;*.png','ÇëÑ¡ÔñÒ»·ùͼÏñ');

if file == 0 warndlg('ÄãµÃÊäÈëÒ»·ùͼÏñ');

%¾¯¸æ¶Ô»°¿òÌáʾÊäÈëºÏ·¨Í¼ÏñÎļþ

else I = imread(fullfile(path,file));

axes(handles.axes1);

imshow(I);

handles.I = I;

end

% Update handles structure

guidata(hObject,handles);

% hObject handle to OpenFile (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 noise.

function noise_Callback(hObject, eventdata, handles)

I = handles.I;

I = imnoise(I,'salt & pepper',0.04); %¼Ó½·ÑÎÔëÉù¡£ÔëÉùÇ¿¶ÈΪ0.04

axes(handles.axes2);

imshow(I,[]);title('¼Ó½·ÑÎÔëÉù');

handles.I = I;

% hObject handle to noise (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 Exit.

function Exit_Callback(hObject, eventdata, handles)

close(gcf) %¹Ø±Õµ±Ç°Figure´°¿Ú¾ä±ú

% hObject handle to Exit (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 filter2.

function filter2_Callback(hObject, eventdata, handles)

I = handles.I;

h0 = 1/9.*[1 1 1 1 1 1 1 1]; %¶¨Òåƽ»¬Ä£°å

g0 = filter2(h0,I);

axes(handles.axes3);

imshow(g0,[]);title('µÍͨÂ˲¨');

% hObject handle to filter2 (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 medfilt2.

function medfilt2_Callback(hObject, eventdata, handles)

I = handles.I;

M = medfilt2(I); %¶þάÖÐÖµÂ˲¨

axes(handles.axes4);

imshow(M);title('¶þάÖÐÖµÂ˲¨');

handles.M = M;

% hObject handle to medfilt2 (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 Roberts.

function Roberts_Callback(hObject, eventdata, handles)

R = handles.I;

BW = edge(R,'roberts',0.1); %¶ÔͼÏñÇóÂÞ²®´ÄÌݶÈ

axes(handles.axes3);

imshow(BW,[]);title('robertsËã×Ó');

% hObject handle to Roberts (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 Laplacian.

function Laplacian_Callback(hObject, eventdata, handles)

L = handles.I;

H = [0 -1 0;-1 4 -1;0 -1 0];

J = imfilter(L,H);

handles.J = J;

axes(handles.axes4);

imshow(J,[]);title('À­ÆÕÀ­Ë¹Ëã×Ó');

% hObject handle to Laplacian (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 imhist.

function imhist_Callback(hObject, eventdata, handles)

I = handles.I;

axes(handles.axes2);

imhist(I);title('ԭʼͼÏñÖ±·½Í¼');

% hObject handle to imhist (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 linear.

function linear_Callback(hObject, eventdata, handles)

I = handles.I;

J = imadjust(I,[0.3 0.7],[]); %ʹÓÃimadjustº¯Êý½øÐлҶȵÄÏßÐԱ任

axes(handles.axes3);imshow(J);title('ÏßÐԱ任');

axes(handles.axes4);imhist(J);title('ÏßÐԱ任ֱ·½Í¼'); %ÏÔʾ±ä»»ºóµÄͼÏñÖ±·½Í¼

% hObject handle to linear (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 histeq.

function histeq_Callback(hObject, eventdata, handles)

I = handles.I;

J = histeq(I); %Íê³ÉÖ±·½Í¼¾ùºâ»¯

axes(handles.axes5);

imshow(J);title('¾ùºâ»¯ºóͼÏñ');

axes(handles.axes6);

imhist(J);title('¾ùºâ»¯µÄÖ±·½Í¼');

% hObject handle to histeq (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 Clean.

function Clean_Callback(hObject, eventdata, handles)

I = ones(256,256);

axes(handles.axes1);imshow(I);

axes(handles.axes2);imshow(I);

axes(handles.axes3);imshow(I);

axes(handles.axes4);imshow(I);

axes(handles.axes5);imshow(I);

axes(handles.axes6);imshow(I);

% hObject handle to Clean (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

function edit7_Callback(hObject, eventdata, handles)

% hObject handle to edit7 (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 edit7 as text

% str2double(get(hObject,'String')) returns contents of edit7 as a double

% --- Executes during object creation, after setting all properties.

function edit7_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit7 (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

七、 实验结果

八、 思考题

(1) 结合教材第6章介绍的图像增强编程方法,说明采用GUIDE环境开发在此方面具有的特点。

图形用于界面(Graphical User Interfaces,GUI)是提供人机交互的工具和方法。GUI是包含图形对象(如窗口、图标、菜单和文本)的用户界面。以某种方式选择或激活这些对象时,通常会引起动作或者发生变化。一个设计优秀的GUI能够非常直观的让用户知道如何操作MATLAB界面,并且了解设计者的开发意图。MATLAB的GUI为开发者提供了一个不脱离MATLAB的开发环境,有助于MATLAB程序的GUI集成。这样可以使开发者不必理会一大堆烦杂的代码,简化程序,但是同样可以实现向决策者提供图文并茂的界面,甚至达到多媒体的效果。可以说MATLAB提供了一个简便的开发环境,可以让开发者快速上手,提高了开发者的工作效率。

所谓的GUIDE就是图形用户界面开发环境(Graphical User Interface Development Environment),它向用户提供了一系列的创建用户图形界面的工具。这些工具大大简化了GUI设计和生成的过程。GUIDE可以完成的任务有如下两点:1)输出GUI。2)GUI编程。GUIDE实际上是一套MATLAB工具集,它主要由七部分组成:版面设计器、属性编辑器、菜单编辑器、调整工具、对象浏览器、Tab顺序编辑器、M文件编辑器。

本文来源:https://www.2haoxitong.net/k/doc/e4102ad9ac02de80d4d8d15abe23482fb4da02b5.html

《数字图像处理实验四、基于GUIDE的图像处理软件开发.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式