質問編集履歴

1

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

2017/08/28 16:10

投稿

r3y2u1
r3y2u1

スコア14

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