-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpic_comp.py
59 lines (45 loc) · 1.37 KB
/
pic_comp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 3 23:39:47 2017
@author: s-ohashi
"""
import os
import itertools
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
####PARAMETER#####################
#リサイズ後の画像サイズ。余白は黒くなります。
width = 512
height = 512
#画像を同一とみなす相関係数
same_thres=0.95
#入力画像一覧
pic_dir="./pic/"
#出力画像一覧
export_pic_dir="./export_pic/"
################################
files = os.listdir(pic_dir)
pic_list=[]
for file in files:
# print(file)
img = Image.open(pic_dir+file)
img.thumbnail((width,height),Image.ANTIALIAS)
bg = Image.new("RGBA",[width,height],(0,0,0,255))
bg.paste(img,(int((width-img.size[0])/2),int((height-img.size[1])/2)))
# plt.imshow(bg)
# plt.show()
pic_list.append(np.array(bg).flatten())
seq=range(len(pic_list))
comb_files=list(itertools.combinations(seq,2))
ommit_list=set()
for idx in comb_files:
# print(idx)
correL_val=np.corrcoef( pic_list[idx[0]], pic_list[idx[1]] )[0,1]
# print(correL_val)
if(correL_val>same_thres):
ommit_list.add(idx[1])
out_list = set(seq) - ommit_list
for o in out_list:
pilImg = Image.fromarray(np.uint8( pic_list[o].reshape([width,height,4]) ))
pilImg.save(export_pic_dir+'%s.png'%o)