開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
-
パッケージ
- PIL(Python Image Library, Pillow)
- NumPy
- SciPy
- matplotlib
実践 コンピュータビジョン (Jan Erik Solem (著)、相川 愛三 (翻訳)、オライリージャパン)の2章(画像の局所記述子)、2.4(演習問題)3.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
from PIL import Image
import numpy as np
from scipy import ndimage
import matplotlib.pyplot as plt
import harris
import fast9 as fast
# fastはpython2向けでpython3で使うためには修正する必要がある。
# xrange関数をrange関数に変更
# 除算「/」を「//」に変更
# (変更しない切り捨てにならず、とcorner_score関数内のループが終了しない
print('3.')
def plot_harris_points(image, filtered_coords):
plt.figure()
plt.gray()
plt.subplots_adjust(0, 0, 1, 1, 0, 0)
plt.imshow(image)
print(f'harris: {len(filtered_coords)}')
plt.plot([p[1] for p in filtered_coords],
[p[0] for p in filtered_coords], '*')
plt.axis('off')
plt.savefig(f'sample3_harris.jpg')
plt.close()
def plot_fast_points(image, filtered_coords):
plt.figure()
plt.gray()
plt.subplots_adjust(0, 0, 1, 1, 0, 0)
plt.imshow(image)
print(f'fast: {len(filtered_coords)}')
plt.plot([p[0] for p in filtered_coords],
[p[1] for p in filtered_coords], '*')
plt.axis('off')
plt.savefig(f'sample3_fast.jpg')
plt.close()
filename = 'building1.jpg'
image = np.array(Image.open(filename).convert('L'))
harris_image = harris.compute_harris_response(image)
flattered_coords = harris.get_harris_points(harris_image, 6)
plot_harris_points(image, flattered_coords)
flattered_corrds, _ = fast.detect(image, 150, False)
plot_fast_points(image, flattered_corrds)
入出力結果(Terminal, cmd(コマンドプロンプト), Jupyter(IPython))
$ ./sample3.py 3. harris: 213 fast: 253 $
元の画像
Harrisコーナー検出器
FASTコーナー検出器
両者のコーナーの検出数を大体同じにして比較してみると、Harrisコーナー検出器は画像の下の部分の木の先端を角として検出してるのに対して、FASTコーナー検出器はビルの窓枠をより多く角として検出してる印象。
0 コメント:
コメントを投稿