báo cáo bài tập lớn xử lý ảnh và tiếng nói kỹ thuật phân đoạn ảnh - Pdf 25



ĐẠI HỌC QUỐC GIA THÀNH PHỐ HỒ CHÍ MINH
TRƯỜNG ĐẠI HỌC BÁCH KHOA
KHOA ĐIỆN – ĐIỆN TỬ Giáo viên giảng dạy: Đỗ Hồng Tuấn
Sinh viên thực hiện:
Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457 TP.HCM 12/2012
Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457

2
b

giữa hai đoạn trên đồ thị đạt cực đại. Giá trị
2
b

được định nghĩa như sau:
2
22
2
11
2
)()(
ttb
mmamma 

,
Thay
2211
mamam
t

,
1
21
 aa
, ta được:
2
2121

jpa
j
Ci
ij
: tổng xác suất trên đoạn j
Trong đó
i
p
là thương của số lần xuất hiện của mức xám thứ i và tổng số lần xuất hiện của tất cả các
mức xám cho nên,
,1
1
0




I
i
i
p

Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457 Báo cáo bài tập Xử Lý Ảnh & Tiếng Nói Page 3

Với I biểu diễn tổng số những mức xám. Thông thường, đối với ảnh văn bản, I có giá trị là 256.
1

Đầu tiên nhóm em xây dựng giao diện cho chương trình như sau:

Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457 Báo cáo bài tập Xử Lý Ảnh & Tiếng Nói Page 5
Ví dụ sau đây sẽ thực hiện phân đoạn ảnh dấu vân tay:
1).Từ màn hình giao diện ấn nút chọn ảnh:
2).Trong thư mục images chọn ảnh “fingerprint.tif”
3).Sau khi ấn nút Open ta sẽ thấy trên giao diện xuất hiện ảnh vừa chọn và histogram của nó.
4).Tiếp theo ta ấn nút Tìm Ngưỡng và nút Phân đoạn ảnh, trên giao điện sẽ xuất hiện giá trị
ngưỡng T và kết quả phân đoạn ảnh theo ngưỡng T vừa tìm.
Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457 Báo cáo bài tập Xử Lý Ảnh & Tiếng Nói Page 6


Báo cáo bài tập Xử Lý Ảnh & Tiếng Nói Page 8
Kết quả::
Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457 Báo cáo bài tập Xử Lý Ảnh & Tiếng Nói Page 9
Kết quả phân đoạn ảnh với nhiều ảnh khác nhau: Ảnh được chọn “blobs.tif”

Ảnh không nhiễu
Kết quả theo phương pháp
ngưỡng toàn cục
Kết quả theo phương pháp
Otsu
Giá trị ngưỡng T tìm được
140
140

toàn cục
Kết quả theo phương pháp Otsu
Giá trị ngưỡng T tìm được
108
106
Ảnh có nhiễu Giá trị ngưỡng T tìm được
122
112 Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457 Báo cáo bài tập Xử Lý Ảnh & Tiếng Nói Page 11

Ảnh được chọn “prak1.tif”
Ảnh không nhiễu

Ảnh được chọn “characters.tif”
Ảnh không nhiễu
Kết quả theo phương pháp
ngưỡng toàn cục
Kết quả theo phương pháp
Otsu
Giá trị ngưỡng T tìm được
123
123
Ảnh có nhiễu Giá trị ngưỡng T tìm được
126
126

Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457 Báo cáo bài tập Xử Lý Ảnh & Tiếng Nói Page 13
Nhận xét:
Qua khảo sát các ảnh ta thấy đối với các ảnh bị ảnh hưởng bởi nhiều Gauss nếu đối tượng có
tham xám nổ bật hơn so với nền ảnh thì cả hai phương pháp hoàn toàn có thể loại bỏ được nhiễu

maxval = max(sigma_b_squared);
k = find(sigma_b_squared == maxval);

Chương trình tìm ngưỡng toàn cục “globalthreshold”

function threshold = globalthreshold(img,T0)
T = 0.5 * (max(img(:)) - min(img(:)));
S=size(img);
numelem=S(1)*S(2);
ImgNext = double(img);
Tnext = -T0;
while abs(T-Tnext) > T0
tmp = ImgNext > T;
zeros1 = sum(tmp(:));
zeros2 = numelem - zeros1;
G1 = tmp.*ImgNext;
G2 = (~tmp).*ImgNext;
u1 = sum(G1(:)) / zeros1;
u2 = sum(G2(:)) / zeros2;
Tnext = T;
T = 0.5 * (u1+u2);
end
threshold = round(T);
Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457 Báo cáo bài tập Xử Lý Ảnh & Tiếng Nói Page 14

Chương trình cho phần gia diện “DeTai1.m”

'gui_Singleton', gui_Singleton,
'gui_OpeningFcn', @DeTai1_OpeningFcn,
'gui_OutputFcn', @DeTai1_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 DeTai1 is made visible.
function DeTai1_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 DeTai1 (see VARARGIN)

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

Nguyễn Kim Triển 40902907
Nguyễn Phước Lộc 40901457

s = size(size(I));
if s(2) == 3
I = rgb2gray(I);
end
gauss_set = 0;
axes(handles.AnhGoc);
imshow(I);
axes(handles.histogram);
imhist(I);
assignin('base','I',I);
function T_Callback(hObject, eventdata, handles)
% hObject handle to T (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 T as text
% str2double(get(hObject,'String')) returns contents of T as a double % Executes during object creation, after setting all properties.
function T_CreateFcn(hObject, eventdata, handles)
% hObject handle to T (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'),

set(hObject,'BackgroundColor','white');
end % Executes on button press in TinhNguongToanCuc.
function TinhNguongToanCuc_Callback(hObject, eventdata, handles)
% hObject handle to TinhNguongToanCuc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I;
global I_noise;
global gauss_set;
global T;
T0 = str2num(get(handles.T0,'String'));
if gauss_set == 1
T = globalthreshold(I_noise,T0);
set(handles.T,'String',T);
assignin('base','T_noise',T);
else
T = globalthreshold(I,T0);
set(handles.T,'String',T);
assignin('base','T',T);
end function T_kq_Callback(hObject, eventdata, handles)
% hObject handle to T (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


global I_noise;
global gauss_set;
if gauss_set == 1;
I1 = segmentation(I_noise,T);
axes(handles.Toancuc_gauss);
imshow(I1,[]);
else
I1 = segmentation(I,T);
axes(handles.Toancuc);
imshow(I1,[]);
end % Executes on button press in Gauss.
function Gauss_Callback(hObject, eventdata, handles)
% hObject handle to Gauss (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I;
global I_noise;
global gauss_set;
m = str2num(get(handles.mean,'String'));
v = str2num(get(handles.variance,'String'));
I_noise = imnoise(I,'gaussian',m,v);
axes(handles.AnhGoc);
imshow(I_noise);
axes(handles.histogram);
imhist(I_noise);
assignin('base','I_noise',I_noise);
gauss_set = 1;

end
function variance_Callback(hObject, eventdata, handles)
% hObject handle to variance (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 variance as text
% str2double(get(hObject,'String')) returns contents of variance as a double % Executes during object creation, after setting all properties.
function variance_CreateFcn(hObject, eventdata, handles)
% hObject handle to variance (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 exit.
function exit_Callback(hObject, eventdata, handles)
% hObject handle to exit (see GCBO)

% Executes on button press in Otsu_phandoan.
function Otsu_phandoan_Callback(hObject, eventdata, handles)
% hObject handle to Otsu_phandoan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I;
global k_otsu;
global I_noise;
global gauss_set;
if gauss_set == 1
I2 = segmentation(I_noise,k_otsu);
axes(handles.Otsu_gauss);
imshow(I2,[]);
else
I2 = segmentation(I,k_otsu);
axes(handles.Otsu);
imshow(I2,[]);
end function k_otsu_Callback(hObject, eventdata, handles)
% hObject handle to k_otsu (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 k_otsu as text
% str2double(get(hObject,'String')) returns contents of k_otsu as a double % Executes during object creation, after setting all properties.


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status