-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimilarity_evaluation.py
executable file
·146 lines (77 loc) · 3.13 KB
/
similarity_evaluation.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
Version: 1.5
Summary: Compute the similarity of a pair of images
Author: suxing liu
Author-email: [email protected]
USAGE:
python3 similarity_evaluation.py -o /org_img_path/ -p /pred_img_path/
"""
import subprocess, os
import sys
import argparse
import numpy as np
import pathlib
import os
import glob
import shutil
from pathlib import Path
from scipy.spatial import KDTree
import cv2
import imutils
from image_similarity_measures.evaluate import evaluation
import openpyxl
def similarity_evaluation(image_ori, image_pred):
file_name = Path(image_ori).name
# metrics = ["rmse", "ssim"]
dict_val = evaluation(org_img_path = image_ori, pred_img_path = image_pred, metrics = ["ssim"])
values = [float(x) for x in list(dict_val.values())]
return file_name, values[0]
if __name__ == '__main__':
ap = argparse.ArgumentParser()
ap.add_argument("-o", "--org_img_path", required = True, help = "path to original image file")
ap.add_argument("-p", "--pred_img_path", required = True, help = "path to predicted image file")
ap.add_argument("-ft", "--filetype", required = False, default = "png", help = "Image filetype")
args = vars(ap.parse_args())
# setting path to model file
org_file_path = args["org_img_path"]
pred_file_path = args["pred_img_path"]
ext = args['filetype']
#accquire image file list
filetype = '*.' + ext
org_image_path = org_file_path + filetype
pred_image_path = pred_file_path + filetype
#accquire image file list
org_imgList = sorted(glob.glob(org_image_path))
pred_imgList = sorted(glob.glob(pred_image_path))
#global save_path
n_images = len(org_imgList)
result_list = []
file_name_list = []
#loop execute
for i, (image_ori, image_pred) in enumerate(zip(org_imgList, pred_imgList)):
(file_name, values) = similarity_evaluation(image_ori, image_pred)
result_list.append([file_name, values])
#print(result_list)
#print(type(result_list[0]))
#########################################################################
#trait_file = (os.path.dirname(os.path.abspath(file_path)) + '/' + 'trait.xlsx')
print("Summary: {0} plant images were processed...\n".format(n_images))
trait_file = (org_file_path + '/ssim_value.xlsx')
if os.path.isfile(trait_file):
# update values
#Open an xlsx for reading
wb = openpyxl.load_workbook(trait_file)
#Get the current Active Sheet
sheet = wb.active
sheet.delete_rows(2, sheet.max_row+1) # for entire sheet
else:
# Keep presets
wb = openpyxl.Workbook()
sheet = wb.active
#sheet_leaf = wb.create_sheet()
sheet.cell(row = 1, column = 1).value = 'filename'
sheet.cell(row = 1, column = 2).value = 'ssim'
for row in result_list:
sheet.append(row)
#save the csv file
wb.save(trait_file)