forked from idoneam/producesort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroughcode.py
73 lines (53 loc) · 1.66 KB
/
roughcode.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
import matplotlib.pyplot as plt
from scipy import ndimage as ndi
from math import sqrt
from skimage.feature import blob_dog
from skimage import io, feature, color
from skimage.color import rgb2gray
from scipy import ndimage
from copy import deepcopy
im = io.imread('rot.jpg')
im2 = deepcopy(im)
#got rid of red, combined blue + green
im[:,:,0] = 0
im_grey = rgb2gray(im)
im_grey = ndimage.gaussian_filter(im_grey, 2)
# Compute the Canny filter for two values of sigma
# image must be 2d
edges2 = feature.canny(im_grey, sigma=3)
mask2 = ndi.binary_fill_holes(edges2)
im_edges2 = deepcopy(im2)
for x in range(mask2.shape[0]):
for y in range(mask2.shape[1]):
if (mask2[x,y] == 0):
im_edges2[x,y] = im[x,y] * mask2[x,y]
def in_range(x, y):
# 40% hard coded
centerx = mask2.shape[0]/2
centery = mask2.shape[1]/2
realx = abs(x-centerx)
realy = abs(y-centery)
if (realx**2 + realy**2 < (0.5*centerx)**2):
return True
else:
return False
im_edges2 = rgb2gray(im_edges2)
blobs_dog = blob_dog(im_edges2, min_sigma=2, threshold=0.6)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)
blobs_list = [blobs_dog]
colors = ['lime']
titles = ['Difference of Gaussian']
sequence = zip(blobs_list, colors, titles)
fig, ax = plt.subplots(1, 1, figsize=(9, 3), sharex=True, sharey=True,
subplot_kw={'adjustable': 'box-forced'})
for (blobs, color, title) in (sequence):
ax.set_title(title)
ax.imshow(im2, interpolation='nearest')
for blob in blobs:
y, x, r = blob
c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
if (in_range(x,y)):
ax.add_patch(c)
ax.set_axis_off()
plt.tight_layout()
plt.show()