-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblob.py
More file actions
107 lines (78 loc) · 2.4 KB
/
blob.py
File metadata and controls
107 lines (78 loc) · 2.4 KB
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
import numpy as np
import glob
import matplotlib.pyplot as plt
from matplotlib import cm
from skimage.feature import hessian_matrix, hessian_matrix_eigvals
from skimage import io
from scipy.misc import imsave
from scipy import signal
from skimage import feature
from skimage import measure
from skimage import filters
import scipy.ndimage as nd
from skimage import morphology as morph
from skimage.morphology import square
sortedGlob = sorted(glob.glob("pdc/sdata/Vid89_good/*.bmp"))
images = [io.imread(file,as_gray=True) for file in sortedGlob]
img_array = np.array(images)
signma_c = 1
s_h = 2.5
a, b = 560, 450
n = 1112
m = 1024
r = 470
y,x = np.ogrid[-a:n-a, -b:m-b]
mask = x*x + y*y >= r*r
for index in range(img_array.shape[0]):
r = 455
mask = x*x + y*y >= r*r
crop = img_array[index]
crop[mask] = True
hxx, hyy, hxy = hessian_matrix(crop, sigma=s_h,
order='xy')
i1, i2 = hessian_matrix_eigvals(hxx, hxy, hyy)
thresh=0.0012
i_t2 = i2 > -thresh
r = 435
mask = x*x + y*y >= r*r
i_t2[mask] = True
mor = np.logical_not(i_t2)
m9 = morph.erosion(mor)
#m11 = morph.opening(mor, square(3))
m6 = morph.remove_small_objects(m9, min_size=240, connectivity=30)
m12 = morph.dilation(m6)
m7 = morph.closing(m12)
m7 = m7.astype(int)
blobs = m7 > 1 * m7.mean()
all_labels = measure.label(blobs)
blobs_labels = measure.label(blobs, background=0)
fig1, axe1 = plt.subplots(1, 5, figsize=(15, 6))
ax1 = axe1.ravel()
ax1[0].imshow(crop, cmap=cm.gray)
ax1[0].set_title('Input Image')
ax1[1].imshow(i2, cmap=cm.gray)
ax1[1].set_title('Hessian sig='+str(s_h))
ax1[2].imshow(mor, cmap=cm.gray)
ax1[2].set_title('Threshold ='+str(thresh))
ax1[3].imshow(m9, cmap=cm.gray)
ax1[3].set_title('Morphology opening')
ax1[4].imshow(m7, cmap=cm.gray)
ax1[4].set_title('Morphology comb')
plt.tight_layout()
fig1.savefig('pdc/blob/' +str(index) +'.jpg')
plt.close()
fig2, axe2 = plt.subplots(1, 4, figsize=(15, 6))
ax2 = axe2.ravel()
ax2[0].imshow(crop, cmap=cm.gray)
ax2[0].set_title('Input Image')
ax2[1].imshow(m7, cmap=cm.gray)
ax2[1].set_title('Morphology comb')
ax2[2].imshow(all_labels, cmap='spectral')
ax2[2].set_title('Blob')
ax2[3].imshow(blobs_labels, cmap='spectral')
ax2[3].set_title('Blob')
plt.tight_layout()
fig2.savefig('pdc/blob/' +'blob'+str(index) +'.jpg')
plt.close()
print(index)
#20,000fps