Tham khảo: Code chương trình xử lý ảnh tổng hợp cơ bản

Giới thiệu

Dưới đây là đề cương ôn tậρ môn xử lý ảnh với matlab củα mình, υiết theo ý hiểu dựα υào các tài liệu thαm khảo khác khi học, cũng có những bài mình chiα sẻ lại (có ghi theo nguồn bài υiết), mọi người thαm khảo υà đóng góρ ý kiến nhα!


Hình minh họa chương trình xử lý ảnh matlab cơ bản tổng hợp

function varargout = xulyanh(varargin)
% XULYANH M-file for xulyanh.fig
% XULYANH, by itself, creates a new XULYANH or raises the existing
% singleton*.
%
% H = XULYANH returns the handle to a new XULYANH or the handle to
% the existing singleton*.
%
% XULYANH(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in XULYANH.M with the given input arguments.
%
% XULYANH(‘Property’,’Value’,…) creates a new XULYANH or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before xulyanh_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to xulyanh_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 xulyanh

% Last Modified by GUIDE v2.5 07-Nov-2016 09:30:00

% Begin initialization code – DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @xulyanh_OpeningFcn, …
‘gui_OutputFcn’, @xulyanh_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 xulyanh is made visible.
function xulyanh_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 xulyanh (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes xulyanh wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% — Outputs from this function are returned to the command line.
function varargout = xulyanh_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 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 A;
[a,b]= uigetfile({‘*.jpg’;’*.png’;’*.tif’;’*.bmp’},’Chon anh’);
A= imread([b,a]);
imshow(A);

% — 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 A;
imshow(A);

% — 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 A;
G= rgb2gray(A);
imshow(G);

% — Executes on button press in anhamban.
function anhamban_Callback(hObject, eventdata, handles)
% hObject handle to anhamban (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global A;
G= rgb2gray(A);
L= max(max(G));
AB= L-G;
imshow(AB);

% — Executes on button press in nhieu.
function nhieu_Callback(hObject, eventdata, handles)
% hObject handle to nhieu (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global A;
I= imnoise(A,’salt & pepper’ ,0.02);
imshow(I);

% — Executes on button press in hs.
function hs_Callback(hObject, eventdata, handles)
% hObject handle to hs (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global A;
G=rgb2gray(A);
imhist(G);

function nguong_Callback(hObject, eventdata, handles)
% hObject handle to nguong (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 nguong as text
% str2double(get(hObject,’String’)) returns contents of nguong as a double

% — Executes during object creation, after setting all properties.
function nguong_CreateFcn(hObject, eventdata, handles)
% hObject handle to nguong (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 tinhtoan.
function tinhtoan_Callback(hObject, eventdata, handles)
% hObject handle to tinhtoan (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global A;
G =rgb2gray(A);
SS = str2double(get(handles.nguong,’string’));
m= size(G,1);
n=size(G,2);
for a=1 : m
for b=1 : n
if G(a,b) < SS
T(a,b)=1;
else
T(a,b)=0;
end
end
end
imshow(T);

% — Executes on button press in kt1.
function kt1_Callback(hObject, eventdata, handles)
% hObject handle to kt1 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global A;
G=rgb2gray(A);
R= edge(G,’roberts’);
imshow(R);
m=size(R,1);
n=size(R,2);
dem=0;
for a=1 : m
for b=1: n
if R(a,b) == 0
dem=dem+1;
end
end
end
temp= num2str(dem);
set(handles.chieudai,’string’,temp)

% — Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% 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)
global A;
G=rgb2gray(A);
S = edge(G,’sobel’);
imshow(S);
m=size(S,1);
n=size(S,2);
dem=0;
for a=1 : m
for b=1: n
if S(a,b) == 0
dem=dem+1;
end
end
end
temp= num2str(dem);
set(handles.chieudai,’string’,temp)

% — Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global A;
G=rgb2gray(A);
P= edge(G,’prewitt’);
imshow(P);
m=size(P,1);
n=size(P,2);
dem=0;
for a=1 : m
for b=1: n
if P(a,b) == 0
dem=dem+1;
end
end
end
temp= num2str(dem);
set(handles.chieudai,’string’,temp)

% — Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (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 thoat.
function thoat_Callback(hObject, eventdata, handles)
% hObject handle to thoat (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 pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global A;
TB= FSPECIAL(‘average’,[3,3]);
Y= imfilter(A,TB);
imshow(Y);
% — Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% 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)
global A;
SN= FSPECIAL (‘sobel’);
I= imfilter(A,SN);
imshow(I);


Bạn nào cần file chạy luôn thì ib mình để tham khảo nha!


Sưu tầm & Chiα sẻ kiến thức

Mọi người thαm khảo υà đóng góρ ý kiến bổ sung nhα!

Việt Hoàng

12 Lạng Sơn! KB Zalo: ⓿❽❻❾❼❾❻❾❻❼

Trả lời

Email của bạn sẽ không được hiển thị công khai.