-
Notifications
You must be signed in to change notification settings - Fork 13
/
main_script.m
79 lines (62 loc) · 2.47 KB
/
main_script.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function main_script()
clc;
addpath('./implementation')
result_matrix = zeros(10,6);
threshold_matrix = zeros(10,6);
for i = 0 : 9
I = imread(['./data/sample' num2str(i) '.tif']);
h = entropy_otsu(I);
result_matrix(i+1,1) = pixel_count(I, h);
threshold_matrix(i+1,1) = h;
h = my_otsu(I);
result_matrix(i+1,2) = pixel_count(I, h);
threshold_matrix(i+1,2) = h;
h = valley_emphasis(I);
result_matrix(i+1,3) = pixel_count(I, h);
threshold_matrix(i+1,3) = h;
h = neighbor_valley_emphasis(I,5);
result_matrix(i+1,4) = pixel_count(I, h);
threshold_matrix(i+1,4) = h;
h = gaussian_valley_emphasis(I,5);
result_matrix(i+1,5) = pixel_count(I, h);
threshold_matrix(i+1,5) = h;
h = lda_valley_emphasis(I);
result_matrix(i+1,6) = pixel_count(I, h);
threshold_matrix(i+1,6) = h;
end
fprintf('Table 1. Pixel counts of defect regions.\n')
fprintf([repmat('-',1,70) '\n'])
fprintf('Image # Proposed method Valley-emphasis Neighbor-VE Fisher''s LDA\n');
fprintf([repmat('-',1,70) '\n'])
for i = 1 : 10
fprintf([num2str(i) '\t ' ...
num2str(result_matrix(i,1)) '\t\t ' ...
num2str(result_matrix(i,3)) '\t\t ' ...
num2str(result_matrix(i,4)) '\t\t ' ...
num2str(result_matrix(i,6)) '\n']);
end
fprintf([repmat('-',1,70) '\n\n'])
fprintf('Table 2. Output thresholds.\n')
fprintf([repmat('-',1,70) '\n'])
fprintf('Image # Proposed method Valley-emphasis Neighbor-VE Fisher''s LDA\n');
fprintf([repmat('-',1,70) '\n'])
for i = 1 : 10
fprintf([num2str(i) '\t ' ...
num2str(threshold_matrix(i,1)) '\t\t ' ...
num2str(threshold_matrix(i,3)) '\t\t ' ...
num2str(threshold_matrix(i,4)) '\t\t ' ...
num2str(threshold_matrix(i,6)) '\n']);
end
fprintf([repmat('-',1,70) '\n'])
rmpath('./implementation')
end
function output = pixel_count( img, threshold )
img = im2bw(img, threshold/255);
% if the thresholded image is mainly black, white pixels are supposed
% to be abnormal, and vice versa
if sum(sum(img == 0)) > sum(sum(img == 1))
output = sum(sum(img == 1));
else
output = sum(sum(img == 0));
end
end