M-file của chương trình

Một phần của tài liệu Tìm hiểu lập trình trong matlab tìm hiểu và hướng dẫn sử dụng image processing (Trang 37 - 50)

function varargout = finaldoan(varargin)

% FINALDOAN MATLAB code for finaldoan.fig

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

% singleton*.

%

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

% the existing singleton*.

%

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

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

%

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

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

% applied to the GUI before finaldoan_OpeningFcn gets called. An

% unrecognized property name or invalid value makes property application

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

Sinh Viên: Nguyễn Trường Giang Page 33

% Edit the above text to modify the response to help finaldoan

% Last Modified by GUIDE v2.5 12-May-2014 21:26:10

% Begin initialization code - DO NOT EDIT gui_Singleton = 1;

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

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @finaldoan_OpeningFcn, ...

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

function finaldoan_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 finaldoan (see VARARGIN)

% Choose default command line output for finaldoan handles.output = hObject;

% Update handles structure guidata(hObject, handles);

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

% uiwait(handles.figure1);

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

function varargout = finaldoan_OutputFcn(hObject, eventdata, handles)

% varargout cell array for returning output args (see VARARGOUT);

Sinh Viên: Nguyễn Trường Giang Page 34

% 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 loadanh.

function loadanh_Callback(hObject, eventdata, handles)

% hObject handle to loadanh (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) global image1 orimage var1 var

var=0;

[filename,pathname,filterindex]=uigetfile({'*.jpg;*.bmp;*.tif;*.tiff;*.jpeg;*.png'},'Add image');

S=imread([pathname,filename]);

S1=rgb2gray(S);

handles.axes=S1;

subplot(handles.axes1);

imshow(S1),title('ANH GOC');

guidata(hObject,handles);

% --- Executes on button press in Salt.

function Salt_Callback(hObject, eventdata, handles)

% hObject handle to Salt (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

g=imnoise(f, 'salt & pepper', 0.04);

figure,imshow(g);

guidata(hObject,handles);

% --- Executes on button press in Gaussian.

function Gaussian_Callback(hObject, eventdata, handles)

% hObject handle to Gaussian (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

g=imnoise(f, 'gaussian', 0.01,0.03);

figure,imshow(g);

guidata(hObject,handles);

Sinh Viên: Nguyễn Trường Giang Page 35

% --- Executes on button press in loctb55.

function pushbutton5_Callback(hObject, eventdata, handles)

% 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) f=handles.axes;

g=imnoise(f, 'salt & pepper', 0.04);

w = fspecial('average', [5,5]);

f1 = imfilter(g, w);

%figure,imshow(g)

%guidata(hObject,handles);

figure,imshow(f1)

guidata(hObject,handles);

% --- Executes on button press in loctb33.

function loctb33_Callback(hObject, eventdata, handles)

% hObject handle to loctb33 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

g=imnoise(f, 'salt & pepper', 0.04);

w = fspecial('average', [3,3]);

f1 = imfilter(g, w);

%figure,imshow(g),title('anh bi nhieu');

%guidata(hObject,handles);

figure,imshow(f1),title('loc nhieu voi bo loc trung binh (diem giua)');

guidata(hObject,handles);

% --- Executes on button press in loctb9x9.

function loctb9x9_Callback(hObject, eventdata, handles)

% hObject handle to loctb9x9 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

g=imnoise(f, 'salt & pepper', 0.04);

w = fspecial('average', [9,9]);

f1 = imfilter(g, w);

%figure,imshow(g),title('anh bi nhieu');

%guidata(hObject,handles);

figure,imshow(f1),title('loc nhieu voi bo loc trung binh (diem giua)');

guidata(hObject,handles);

Sinh Viên: Nguyễn Trường Giang Page 36

% --- Executes on button press in locdiemgiua55.

function locdiemgiua55_Callback(hObject, eventdata, handles)

% hObject handle to locdiemgiua55 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

g=imnoise(f, 'salt & pepper', 0.04);

w = fspecial('average', [5,5]);

f1 = imfilter(g, w);

%figure

%imshow(g),title('anh bi nhieu');

figure

imshow(f1),title('loc voi bo loc diem voi ma tran 5x5');

guidata(hObject,handles);

% --- Executes on button press in loccaocap33.

function loccaocap33_Callback(hObject, eventdata, handles)

% hObject handle to loccaocap33 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

g=imnoise(f, 'salt & pepper', 0.04);

f1=ordfilt2(g,5,ones(3,3));

figure,imshow(f1)

% --- Executes on button press in locdiemgiua33.

function locdiemgiua33_Callback(hObject, eventdata, handles)

% hObject handle to locdiemgiua33 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

g=imnoise(f, 'salt & pepper', 0.04);

w = fspecial('average', [3,3]);

f1 = imfilter(g, w);

%figure

%imshow(g),title('anh bi nhieu');

figure

imshow(f1),title('loc voi bo loc diem voi ma tran 3x3');

guidata(hObject,handles);

% --- Executes on button press in locdiemgiua99.

function locdiemgiua99_Callback(hObject, eventdata, handles)

% hObject handle to locdiemgiua99 (see GCBO)

Sinh Viên: Nguyễn Trường Giang Page 37

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

g=imnoise(f, 'salt & pepper', 0.04);

w = fspecial('average', [9,9]);

f1 = imfilter(g, w);

%figure

%imshow(g),title('anh bi nhieu');

figure

imshow(f1),title('loc voi bo loc diem voi ma tran 9x9');

guidata(hObject,handles);

% --- Executes on button press in loctuongthich33.

function loctuongthich33_Callback(hObject, eventdata, handles)

% hObject handle to loctuongthich33 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

f1 = wiener2(f,[3,3]);

figure

imshow(f1),title('Anh loc tuong thich voi mat la 3x3');

guidata(hObject,handles);

% --- Executes on button press in loccaocap55.

function loccaocap55_Callback(hObject, eventdata, handles)

% hObject handle to loccaocap55 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

f1=ordfilt2(f,12,ones(5,5));

figure,imshow(f1)

% --- Executes on button press in loccaocap99.

function loccaocap99_Callback(hObject, eventdata, handles)

% hObject handle to loccaocap99 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

f1=ordfilt2(f,36,ones(9,9));

figure,imshow(f1)

% --- Executes on button press in loctuongthich55.

Sinh Viên: Nguyễn Trường Giang Page 38 function loctuongthich55_Callback(hObject, eventdata, handles)

% hObject handle to loctuongthich55 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

f1 = wiener2(f,[5,5]);

figure

imshow(f1),title('Anh loc tuong thich voi mat la 5x5');

guidata(hObject,handles);

% --- Executes on button press in loctuongthich99.

function loctuongthich99_Callback(hObject, eventdata, handles)

% hObject handle to loctuongthich99 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

f1 = wiener2(f,[9,9]);

figure

imshow(f1),title('Anh loc tuong thich voi mat la 9x9');

guidata(hObject,handles);

% --- Executes on button press in medfilt.

function medfilt_Callback(hObject, eventdata, handles)

% hObject handle to medfilt (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

f3=filter2(fspecial('average',3),f)/255;

f2=medfilt2(f3, [3 3]);

figure

imshow(f2),title('Anh loc voi medfilt mat 3x3');

guidata(hObject,handles);

% --- Executes on button press in medfilt55.

function medfilt55_Callback(hObject, eventdata, handles)

% hObject handle to medfilt55 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

f3=filter2(fspecial('average',5),f)/255;

f2=medfilt2(f3, [5 5]);

figure

imshow(f2),title('Anh loc voi medfilt mat 5x5');

Sinh Viên: Nguyễn Trường Giang Page 39 guidata(hObject,handles)

% --- Executes on button press in medfilt99.

function medfilt99_Callback(hObject, eventdata, handles)

% hObject handle to medfilt99 (see GCBO)

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

% handles structure with handles and user data (see GUIDATA) f=handles.axes;

f3=filter2(fspecial('average',9),f)/255;

f2=medfilt2(f3, [9 9]);

figure

imshow(f2),title('Anh loc voi medfilt mat 3x3');

guidata(hObject,handles)

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

function axes2_CreateFcn(hObject, eventdata, handles)

% hObject handle to axes2 (see GCBO)

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

% handles empty - handles not created until after all CreateFcns called imshow('D:\New folder (2)\R2012\bin\1.jpg');

% Hint: place code in OpeningFcn to populate axes2

1.2 Một số hình ảnh của test chương trình với hình ảnh bị nhiễu muối tiêu

Hình 4.2 Ảnh bị nhiễu muối tiêu( salt&papper)

Sinh Viên: Nguyễn Trường Giang Page 40 Hình 4.3 Ảnh lọc với bộ lọc trung bình 3x3

Hình 4.4 Hình ảnh với bộ lọc trung bình 5x5

Sinh Viên: Nguyễn Trường Giang Page 41 Hình 4.5 Hình ảnh với bộ lọc cao cấp 3x3

Hình 4.6: hình ảnh với bộ lọc cao cấp 5x5

Sinh Viên: Nguyễn Trường Giang Page 42 1.3 hình ảnh test của chương trình với hình ảnh bị nhiễu Gaussian

Hình4.7 Hình ảnh bị nhiễu Gaussian

Hình 4.8 Hình ảnh với bộ lọc điểm giữa ma trận 3x3

Sinh Viên: Nguyễn Trường Giang Page 43 Hình 4.9 hình ảnh với bộ lọc điểm giữa ma trận 5x5

Hình 4.10 hình ảnh với bộ lọc tương thích với mắt là 3x3

Sinh Viên: Nguyễn Trường Giang Page 44 Hình 4.11 Hình ảnh với bộ lọc tương thích với mắt là 5x5

Một phần của tài liệu Tìm hiểu lập trình trong matlab tìm hiểu và hướng dẫn sử dụng image processing (Trang 37 - 50)

Tải bản đầy đủ (PDF)

(51 trang)