-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment_scripts.py
130 lines (105 loc) · 4.23 KB
/
experiment_scripts.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from utils import *
from vanilla_algorithm import *
from optimisation_one import *
from optimisation_two import *
from BlurType import BLUR_TYPE
folder_path = 'data/'
pts_file = 'pts.mat'
#----------------------------------------------------------------------#
'''
Experiment Set 1 - Three experiments with pts.mat data
'''
'''
Exp 1 -
pts.mat with vanilla meanshift algoritm
'''
def pts_data_vanilla_meanshift():
pts_data = load_pts_data(folder_path+pts_file)
start_time = getCurrTime()
labels, peaks = meanshift(pts_data, 2)
end_time = getCurrTime()
compute_time = computeTime(start_time, end_time)
return labels, peaks, compute_time
'''
Exp 2 -
pts.mat with meanshift optimisation 1 algoritm
'''
def pts_data_meanshift_opt_one():
pts_data = load_pts_data(folder_path+pts_file)
start_time = getCurrTime()
labels, peaks = meanshift_opt_one(pts_data, 2)
end_time = getCurrTime()
compute_time = computeTime(start_time, end_time)
return labels, peaks, compute_time
'''
Exp 3 -
pts.mat with meanshift optimisation 2 algoritm.
'''
def pts_data_meanshift_opt_two():
pts_data = load_pts_data(folder_path+pts_file)
start_time = getCurrTime()
labels, peaks = meanshift_opt_2(pts_data, r=2, c=4)
end_time = getCurrTime()
compute_time = computeTime(start_time, end_time)
return labels, peaks, compute_time
#----------------------------------------------------------------------#
'''
Experiment set 2 - Experiment different images with second optimisation -
without pre-processing.
'''
def execute_meanshift_opt_2(im, radius, c):
labels, peaks = meanshift_opt_2(im, radius, c)
return im, peaks, labels
def meanshift_seg_opt2_3D(im, radius, c):
data = cv2.cvtColor(im, cv2.COLOR_RGB2LAB)
data = reshape_image(data, DIMENSION.D3)
start_time = getCurrTime()
data, peaks, labels = execute_meanshift_opt_2(data, radius, c)
end_time = getCurrTime()
compute_time = computeTime(start_time, end_time)
segmented_im = generate_segmented_im(labels, peaks, im, DIMENSION.D3)
segmented_im = cv2.cvtColor(segmented_im, cv2.COLOR_LAB2RGB)
return data, peaks, labels, segmented_im, compute_time
def meanshift_seg_opt2_5D(im, radius, c):
data = cv2.cvtColor(im, cv2.COLOR_RGB2LAB)
data = reshape_image(data, DIMENSION.D5)
start_time = getCurrTime()
data, peaks, labels, = execute_meanshift_opt_2(data, radius, c)
end_time = getCurrTime()
compute_time = computeTime(start_time, end_time)
segmented_im = generate_segmented_im(labels, peaks, im, DIMENSION.D5)
segmented_im = cv2.cvtColor(segmented_im, cv2.COLOR_LAB2RGB)
return data, peaks, labels, segmented_im, compute_time
#----------------------------------------------------------------------#
'''
Experiment set 3 - Experiment different images with second optimisation -
with pre-processing - primarily image smoothing.
'''
def meanshift_seg_opt2_3D_preproc(im, radius, c, blurType):
if blurType == BLUR_TYPE.GAUSS:
data = gaussBlur(im)
elif blurType == BLUR_TYPE.MEDIAN:
data = medianBlur(im)
data = cv2.cvtColor(data, cv2.COLOR_RGB2LAB)
data = reshape_image(data, DIMENSION.D3)
start_time = getCurrTime()
data, peaks, labels = execute_meanshift_opt_2(data, radius, c)
end_time = getCurrTime()
compute_time = computeTime(start_time, end_time)
segmented_im = generate_segmented_im(labels, peaks, im, DIMENSION.D3)
segmented_im = cv2.cvtColor(segmented_im, cv2.COLOR_LAB2RGB)
return data, peaks, labels, segmented_im, compute_time
def meanshift_seg_opt2_5D_preproc(im, radius, c, blurType):
if blurType == BLUR_TYPE.GAUSS:
data = gaussBlur(im)
elif blurType == BLUR_TYPE.MEDIAN:
data = medianBlur(image)(im)
data = cv2.cvtColor(data, cv2.COLOR_RGB2LAB)
data = reshape_image(data, DIMENSION.D5)
start_time = getCurrTime()
data, peaks, labels, = execute_meanshift_opt_2(data, radius, c)
end_time = getCurrTime()
compute_time = computeTime(start_time, end_time)
segmented_im = generate_segmented_im(labels, peaks, im, DIMENSION.D5)
segmented_im = cv2.cvtColor(segmented_im, cv2.COLOR_LAB2RGB)
return data, peaks, labels, segmented_im, compute_time