teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

perceptual hashのプログラムを乗せました。

2017/08/28 16:10

投稿

r3y2u1
r3y2u1

スコア14

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,24 @@
1
+ ```python
2
+ コード
3
+ def phash(image, hash_size=8, highfreq_factor=4):
4
+ """
5
+ Perceptual Hash computation.
6
+
7
+ Implementation follows http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
8
+
9
+ @image must be a PIL instance.
10
+ """
11
+ import scipy.fftpack
12
+ img_size = hash_size * highfreq_factor
13
+ image = image.convert("L").resize((img_size, img_size), Image.ANTIALIAS)
14
+ pixels = numpy.array(image.getdata(), dtype=numpy.float).reshape((img_size, img_size))
15
+ dct = scipy.fftpack.dct(scipy.fftpack.dct(pixels, axis=0), axis=1)
16
+ dctlowfreq = dct[:hash_size, :hash_size]
17
+ med = numpy.median(dctlowfreq)
18
+ diff = dctlowfreq > med
19
+ return ImageHash(diff)
20
+
1
- 以前もimagehashについて質問したのですが、
21
+ ```以前もimagehashについて質問したのですが、
2
22
  ・なぜ離散コサイン変換を使うとガンマ補正やヒストグラム補正がかかっている画像でも似たような画像と認識できるのか(Average hash)では異なる画像と認識されてしまうのか
3
23
 
4
24
  ・Average hashでは8x8に縮小していたのにphashでは32×32に縮小していました。DCTを行うには良い大きさらしいですがそれは何故ですか?