-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsobel_test.py
115 lines (93 loc) · 3.51 KB
/
sobel_test.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
from bubble_tools import split_image, x_profile, y_profile, xy_autocorr, acf_variables, sobel
from skimage import io
import os
import pandas as pd
import matplotlib.pyplot as pl
dat_file = '/Users/s1101153/OneDrive - University of Edinburgh/Files/bubbles/confocal_data/tunnels/dat_list_73.csv'
im_folder = '/Users/s1101153/OneDrive - University of Edinburgh/Files/bubbles/confocal_data/tunnels/'
seg_folder = '/Users/s1101153/OneDrive - University of Edinburgh/Files/bubbles/confocal_data/tunnels/model_73'
# %% reading files and opening images
dat_liquid = pd.DataFrame({'chunk_im': [],
'chunk_loc': [],
'distance': []})
dat_particle = pd.DataFrame({'chunk_im': [],
'chunk_loc': [],
'distance': []})
f = open(dat_file, 'r')
for line in f.readlines():
if not line.endswith('x') and line.startswith('Image'):
vals = line.split(',')
im_file = os.path.join(im_folder, vals[0])
liquid_im = io.imread(im_file)[0]
particle_im = io.imread(im_file)[1]
seg_file = os.path.join(seg_folder, vals[1])
seg_im = io.imread(seg_file, as_gray=True)[0]
liquid = split_image(liquid_im, seg_im, 128, 128, 64)
dat_liquid = dat_liquid.append(liquid)
particle = split_image(particle_im, seg_im, 128, 128, 64)
dat_particle = dat_particle.append(particle)
f.close()
dat_liquid = dat_liquid.reset_index(drop=True)
dat_liquid = dat_liquid.astype({'chunk_im': 'object',
'chunk_loc': 'object',
'distance': 'float64'})
print(dat_liquid.describe())
dat_particle = dat_particle.reset_index(drop=True)
dat_particle = dat_particle.astype({'chunk_im': 'object',
'chunk_loc': 'object',
'distance': 'float64'})
print(dat_particle.describe())
# %% sobel filters
# test_im = dat_overlap_all['chunk_im'][0]
# def sobel(im):
# x_kernel = np.array([[-1, 0, 1],
# [-2, 0, 2],
# [-1, 0, 1]])
# y_kernel = np.array([[-1, -2, -1],
# [0, 0, 0],
# [1, 2, 2]])
# kernel_45 = np.array([[-1, -1, 2],
# [-1, 2, -1],
# [2, -1, -1]])
# kernel_neg45 = np.array([[2, -1, -1],
# [-1, 2, -1],
# [-1, -1, 2]])
# sobel_x = ndimage.convolve(im, x_kernel)
# sobel_y = ndimage.convolve(im, y_kernel)
# sobel_45 = ndimage.convolve(im, kernel_45)
# sobel_neg45 = ndimage.convolve(im, kernel_neg45)
#
# return sobel_x, sobel_y, sobel_45, sobel_neg45
x_ims = []
y_ims = []
p45_ims = []
n45_ims = []
for im in dat_particle['chunk_im']:
sobel_x, sobel_y, sobel_45, sobel_neg45 = sobel(im)
x_ims.append(sobel_x)
y_ims.append(sobel_y)
p45_ims.append(sobel_45)
n45_ims.append(sobel_neg45)
# pl.subplot(2, 2, 1)
# pl.imshow(sobel_x)
# pl.title('Sobel filter x')
#
# pl.subplot(2, 2, 2)
# pl.imshow(sobel_y)
# pl.title('Sobel filter y')
#
# pl.subplot(2, 2, 3)
# pl.imshow(sobel_45)
# pl.title('Sobel filter +45deg')
#
# pl.subplot(2, 2, 4)
# pl.imshow(sobel_neg45)
# pl.title('Sobel filter -45deg')
# pl.tight_layout()
# pl.show()
dat_particle['x'] = x_ims
dat_particle['y'] = y_ims
dat_particle['45deg'] = p45_ims
dat_particle['-45deg'] = n45_ims
# %%
dat_particle.head()