開発環境
- 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
- VLFeat(Library、コマンドラインインターフェース)
実践 コンピュータビジョン (Jan Erik Solem (著)、相川 愛三 (翻訳)、オライリージャパン)の2章(画像の局所記述子)、2.4(演習問題)4.を取り組んでみる。
コード(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 sift
print('4.')
filename1 = 'building1.jpg'
filename2 = 'building2.jpg'
filename3 = 'building2_small.jpg'
filename1_sift = filename1.replace('jpg', 'sift')
filename2_sift = filename2.replace('jpg', 'sift')
filename3_sift = filename3.replace('jpg', 'sift')
image1 = np.array(Image.open(filename1).convert('L'))
image2 = np.array(Image.open(filename2).convert('L'))
image3 = np.array(Image.open(filename3).convert('L'))
sift.process_image(filename1, filename1_sift)
sift.process_image(filename2, filename2_sift)
sift.process_image(filename3, filename3_sift)
locs1, desc1 = sift.read_features_from_file(filename1_sift)
locs2, desc2 = sift.read_features_from_file(filename2_sift)
locs3, desc3 = sift.read_features_from_file(filename3_sift)
print(len(desc1), len(desc2), len(desc3))
matchscores = sift.match_twosided(desc1, desc2)
plt.subplots_adjust(0, 0, 1, 1, 0, 0)
sift.plot_matches(image1, image2, locs1, locs2, matchscores)
plt.savefig('sample4_1.jpg')
plt.close()
matchscores = sift.match_twosided(desc1, desc3)
plt.subplots_adjust(0, 0, 1, 1, 0, 0)
sift.plot_matches(image1, image3, locs1, locs3, matchscores)
plt.savefig('sample4_2.jpg')
plt.close()
入出力結果(Terminal, cmd(コマンドプロンプト), Jupyter(IPython))
$ ./sample4.py 4. processed tmp.pgm to building1.sift processed tmp.pgm to building2.sift processed tmp.pgm to building2_small.sift 2659 2199 2028 $
元の建物の画像。
別の角度(と季節)からのビルの画像。
別の角度(と季節)からのビルの画像の解像度を低くした画像。(サイズは同じ)
スケール(解像度)による違い。
0 コメント:
コメントを投稿