# -*- coding: utf-8 -*-
#参考:http://scikit-image.org/
from matplotlib import pyplot as plt
from skimage import data
from skimage.feature import blob_dog, blob_log, blob_doh
from math import sqrt
from skimage.color import rgb2gray
#Ipythonで表示用の設定
%matplotlib inline
#サンプルデータ読込
image = data.hubble_deep_field()[0:500, 0:500]
#グレイスケール変換
image_gray = rgb2gray(image)
#LOGによるブログ解析
blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)
#半径の計算 in the 3rd column.
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)
#DOGによるブログ解析
blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
#半径の計算 in the 3rd column.
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)
#DOHによるブログ解析
blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)
#結果の表示
#結果の統合
blobs_list = [blobs_log, blobs_dog, blobs_doh]
colors = ['yellow', 'lime', 'red']
titles = ['Laplacian of Gaussian', 'Difference of Gaussian',
'Determinant of Hessian']
sequence = zip(blobs_list, colors, titles)
#表示
for blobs, color, title in sequence:
fig, ax = plt.subplots(1, 1)
ax.set_title(title)
ax.imshow(image, interpolation='nearest')
for blob in blobs:
y, x, r = blob
c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
ax.add_patch(c)
plt.show()