-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiments.py
62 lines (52 loc) · 2.87 KB
/
experiments.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
from experiment_scripts import *
from utils import *
from visualisations import *
'''
Experiments with pts.mat data.
'''
def runPointsExperiment():
labels, peaks, compute_time = pts_data_vanilla_meanshift()
print('simple takes - ' + str(compute_time))
labels, peaks, compute_time = pts_data_meanshift_opt_one()
print('Opt 1 takes - ' + str(compute_time))
labels, peaks, compute_time = pts_data_meanshift_opt_two()
print('Opt 2 takes - ' + str(compute_time))
# runPointsExperiment()
'''
Experiments with images.
'''
# 3D segmentation
def segment_img_3D(path, r, c, outname):
image = read_image(path)
data, peaks, labels, segmented_im, compute_time = meanshift_seg_opt2_3D(image, r, c)
show_image('r = '+str(r)+', c = '+str(c) +', 3D, peaks = '+str(len(peaks)) + '\n' +'time: '+str(round(compute_time, 5)) , segmented_im)
name = outname+'_seg3d_'+'_'+'peaks_'+str(len(peaks))+'_'+str(compute_time)+'.png'
save_image(name, segmented_im)
# segment_img_3D('data/big_ben.jpeg', 10, 6, 'mask_man')
# segment_img_3D('data/face_girl_one.png', 20, 12, 'mask_man')
# 5D segmentation
def segment_img_5D(path, r, c, outname):
image = read_image(path)
data, peaks, labels, segmented_im, compute_time = meanshift_seg_opt2_5D(image, r, c)
show_image('r = '+str(r)+', c = '+str(c) +', 5D, peaks = '+str(len(peaks)) + '\n' +'time: '+str(round(compute_time, 5)) , segmented_im)
name = outname+'_seg5d_'+'_'+'peaks_'+str(len(peaks))+'_'+str(compute_time)+'.png'
save_image(name, segmented_im)
# segment_img_5D('data/face_girl_two.png', 20, 12, 'mask_man')
# segment_img_5D('data/face_girl_one.png', 20, 2, 'mask_man')
# 3D segmentation with BLUR
def segment_img_3D_blur(path, r, c, outname, blurType):
image = read_image(path)
data, peaks, labels, segmented_im, compute_time = meanshift_seg_opt2_3D_preproc(image, r, c, blurType)
show_image('r = '+str(r)+', c = '+str(c) +', 3D, peaks = '+str(len(peaks)) + '\n' +'time: '+str(round(compute_time, 5)) + str(blurType) , segmented_im)
name = outname+'_seg3d_blur_'+str(blurType)+'_'+'peaks_'+str(len(peaks))+'_'+str(compute_time)+'.png'
save_image(name, segmented_im)
# segment_img_3D_blur('data/big_ben.jpeg', 10, 2, 'mask_man', BLUR_TYPE.MEDIAN)
# 3D segmentation with BLUR
def segment_img_5D_blur(path, r, c, outname, blurType):
image = read_image(path)
data, peaks, labels, segmented_im, compute_time = meanshift_seg_opt2_5D_preproc(image, r, c, blurType)
show_image('r = '+str(r)+', c = '+str(c) +', 5D, peaks = '+str(len(peaks)) + '\n' +'time: '+str(round(compute_time, 5))+str(blurType), segmented_im)
name = outname+'_seg5d_blur_'+str(blurType)+'_'+'peaks_'+str(len(peaks))+'_'+str(compute_time)+'.png'
save_image(name, segmented_im)
# segment_img_5D('data/face_girl_one.png', 20,3, 'face_girl_one')
# segment_img_3D_blur('data/face_girl_one.png', 5,2, 'face_girl_one', BLUR_TYPE.MEDIAN)