数字图像处理课程的大作业,要求如下:
图像分割就是把图像分成若干个特定的、具有独特性质的区域并提出感兴趣目标的技术和过程。它是由图像处理到图像分析的关键步骤。现有的图像分割方法主要分以下几类:基于阈值的分割方法、基于区域的分割方法、基于边缘的分割方法以及基于特定理论的分割方法等。图像分割后提取出的目标可以用于图像语义识别,图像搜索等等领域。
要求1:输入一副真彩色RGB图像dog.jpg,完成对小狗的分割,输入结果为只包含小狗区域的二值图(matlab环境下,小狗区域值为1,其他区域值为0)。
要求2:设计一个简单的图形用户界面GUI,显示输入图像和输出图像
<pre name="code" class="plain">function varargout = DIP(varargin)
%DIP MATLAB code for DIP.fig %DIP, by itself, creates a new DIP or raises the existing %singleton*. % %H = DIP returns the handle to a new DIP or the handle to %the existing singleton*. % %DIP(‘CALLBACK‘,hObject,eventData,handles,...) calls the local %function named CALLBACK in DIP.M with the given input arguments. % %DIP(‘Property‘,‘Value‘,...) creates a new DIP or raises the %existing singleton*. Starting from the left, property value pairs are %applied to the GUI before DIP_OpeningFcn gets called. An %unrecognized property name or invalid value makes property application %stop. All inputs are passed to DIP_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 DIP %Last Modified by GUIDE v2.5 07-Jun-2015 01:02:20 %Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct(‘gui_Name‘, mfilename, ... ‘gui_Singleton‘, gui_Singleton, ... ‘gui_OpeningFcn‘, @DIP_OpeningFcn, ... ‘gui_OutputFcn‘, @DIP_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 DIP is made visible. function DIP_OpeningFcn(hObject1, ~, handles1, 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 untitled6 (see VARARGIN) im=imread(‘dog.jpg‘); %第一张图片的显示 axes(handles1.axes1); guidata(hObject1, handles1); hold on; imshow(im); handles1.output = hObject1; % Update handles structure guidata(hObject1, handles1); % UIWAIT makes DIP wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = DIP_OutputFcn(~, ~, 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 pushbutton1. function pushbutton1_Callback(axes2, ~,handles2 ) % 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) I=imread(‘dog.jpg‘); I1=rgb2hsv(I); %转到HSV空间 I2=I1(:,:,2); %S分量 BW1=im2bw(I2,0.4); bw1=BW1(80:650,45:680); %分割 peng = strel(‘diamond‘, 2); bw11=imdilate(bw1,peng,‘same‘); %膨胀 bw111=~bw11; %取反 saveas(gcf,‘dog1‘,‘jpg‘); axes(handles2.axes2); guidata(axes2, handles2); hold on; imshow(bw111); %显示处理完成的图片
处理完成的图像,效果还不错:
时间: 2024-10-07 20:42:57