In [1]:
This fails to work on windows

%matplotlib inline

from __future__ import print_function
from __future__ import division
import numpy as np
from matplotlib import pyplot as plt
import cv2
import pylab                                 
pylab.rcParams['figure.figsize'] = (10.0, 18.0)

In [2]:
# to use this, do:  pip install scikit-image

from skimage.feature import blob_dog, blob_log, blob_doh
# blobs_log = blob_log(mask, max_sigma=30, num_sigma=10, threshold=.1)
blobs_log = blob_log(mask, threshold=.5)
print(blobs_log)



ImportErrorTraceback (most recent call last)
<ipython-input-2-1c81c2a63b87> in <module>()
      1 # to use this, do:  pip install scikit-image
      2 
----> 3 from skimage.feature import blob_dog, blob_log, blob_doh
      4 # blobs_log = blob_log(mask, max_sigma=30, num_sigma=10, threshold=.1)
      5 blobs_log = blob_log(mask, threshold=.5)

ImportError: No module named skimage.feature

In [8]:
from math import sqrt
# Compute radii in the 3rd column.
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)
print(blobs_log)



NameErrorTraceback (most recent call last)
<ipython-input-8-b1038bdb37ef> in <module>()
      1 from math import sqrt
      2 # Compute radii in the 3rd column.
----> 3 blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)
      4 print(blobs_log)

NameError: name 'blobs_log' is not defined

In [9]:
tmp = mask.copy()
tmp = cv2.cvtColor(tmp, cv2.COLOR_GRAY2RGB)
for b in blobs_log:
    b = map(int, b)
    y,x,r = b
    cv2.circle(tmp, (x,y), r, (255,0,255))
#     c = plt.Circle((x, y), r, color='yellow', linewidth=2, fill=False)
#     print(dir(c))
#     plt.add_patch(c)
# plt.set_axis_off()
# plt.tight_layout()
plt.imshow(tmp)



NameErrorTraceback (most recent call last)
<ipython-input-9-9a4824c6e000> in <module>()
      1 tmp = mask.copy()
      2 tmp = cv2.cvtColor(tmp, cv2.COLOR_GRAY2RGB)
----> 3 for b in blobs_log:
      4     b = map(int, b)
      5     y,x,r = b

NameError: name 'blobs_log' is not defined

In [10]:
tmp = mask.copy()
tmp = cv2.cvtColor(tmp, cv2.COLOR_GRAY2RGB)
blobs_dog = blob_dog(mask, threshold=.5)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)
for b in blobs_dog:
    b = map(int, b)
    y,x,r = b
    cv2.circle(tmp, (x,y), r, (255,0,255))
plt.imshow(tmp)



NameErrorTraceback (most recent call last)
<ipython-input-10-a0653c50f0df> in <module>()
      1 tmp = mask.copy()
      2 tmp = cv2.cvtColor(tmp, cv2.COLOR_GRAY2RGB)
----> 3 blobs_dog = blob_dog(mask, threshold=.5)
      4 blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)
      5 for b in blobs_dog:

NameError: name 'blob_dog' is not defined

In [6]:
# close up small holes
dilate = cv2.dilate(erode, None, iterations=4)
plt.imshow(dilate, cmap='gray')
plt.title('Dilate');

mask = dilate



In [11]:
tmp = mask.copy()
tmp = cv2.cvtColor(tmp, cv2.COLOR_GRAY2RGB)
blobs_doh = blob_doh(mask, threshold=.05)
for b in blobs_doh:
    b = map(int, b)
    y,x,r = b
    cv2.circle(tmp, (x,y), r, (255,0,255))
plt.imshow(tmp);



NameErrorTraceback (most recent call last)
<ipython-input-11-01ca2318c9bf> in <module>()
      1 tmp = mask.copy()
      2 tmp = cv2.cvtColor(tmp, cv2.COLOR_GRAY2RGB)
----> 3 blobs_doh = blob_doh(mask, threshold=.05)
      4 for b in blobs_doh:
      5     b = map(int, b)

NameError: name 'blob_doh' is not defined

In [12]:
from skimage import measure
contours = measure.find_contours(mask, 0.1)

# Display the image and plot all contours found
fig, ax = plt.subplots()
ax.imshow(mask, cmap='gray')

for n, contour in enumerate(contours):
    ax.plot(contour[:, 1], contour[:, 0], linewidth=2)

ax.axis('image')
# ax.set_xticks([])
# ax.set_yticks([]);
# ax.grid(True)



ImportErrorTraceback (most recent call last)
<ipython-input-12-5ce021b43ed0> in <module>()
----> 1 from skimage import measure
      2 contours = measure.find_contours(mask, 0.1)
      3 
      4 # Display the image and plot all contours found
      5 fig, ax = plt.subplots()

ImportError: No module named skimage

In [13]:
# http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.regionprops
from skimage.measure import label, regionprops

tmp = cv2.cvtColor(mask.copy(), cv2.COLOR_GRAY2RGB)

label_img = label(mask)
regions = regionprops(label_img)

for r in regions:
    print('-'*20)
    print('centroid', r.centroid)
#     print(r.bbox)
#     print('moments_hu', r.moments_hu)
    print('area', r.area)
    print('eccentricity', r.eccentricity)
    y,x = map(int, r.centroid)
    cv2.circle(tmp, (x,y), 5, (255,0,255), -1)
    cv2.rectangle(tmp, (r.bbox[1], r.bbox[0]), (r.bbox[3], r.bbox[2]), (255,0,0))
    
plt.imshow(tmp);



ImportErrorTraceback (most recent call last)
<ipython-input-13-83eec3aece6e> in <module>()
      1 # http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.regionprops
----> 2 from skimage.measure import label, regionprops
      3 
      4 tmp = cv2.cvtColor(mask.copy(), cv2.COLOR_GRAY2RGB)
      5 

ImportError: No module named skimage.measure

['class', 'delattr', 'dict', 'doc', 'eq', 'format', 'getattribute', 'getitem', 'hash', 'init', 'iter', 'module', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_cache', '_cache_active', '_intensity_image', '_intensity_image_double', '_label_image', '_ndim', '_slice', 'area', 'bbox', 'bbox_area', 'centroid', 'convex_area', 'convex_image', 'coords', 'eccentricity', 'equivalent_diameter', 'euler_number', 'extent', 'filled_area', 'filled_image', 'image', 'inertia_tensor', 'inertia_tensor_eigvals', 'intensity_image', 'label', 'local_centroid', 'major_axis_length', 'max_intensity', 'mean_intensity', 'min_intensity', 'minor_axis_length', 'moments', 'moments_central', 'moments_hu', 'moments_normalized', 'orientation', 'perimeter', 'solidity', 'weighted_centroid', 'weighted_local_centroid', 'weighted_moments', 'weighted_moments_central', 'weighted_moments_hu', 'weighted_moments_normalized']


In [ ]: