Skip to content

Commit 0ba3d0f

Browse files
committed
python: fixed bug where update_charts() didn't work on images with different sizes
sewar_rmse() should return 1 metric if the image sizes are different
1 parent 2d5193f commit 0ba3d0f

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

python/inet/test/chart.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,15 @@
2828

2929

3030
def sewar_rmse(a, b):
31-
a,b = sewar_initial_check(a,b)
31+
assert a.shape == b.shape, "Supplied images have different sizes " + \
32+
str(a.shape) + " and " + str(b.shape)
33+
if len(a.shape) == 2:
34+
a = a[:,:,numpy.newaxis]
35+
b = b[:,:,numpy.newaxis]
36+
a = a.astype(numpy.float64)
37+
b = b.astype(numpy.float64)
3238
return numpy.sqrt(numpy.mean((a.astype(numpy.float64)-b.astype(numpy.float64))**2))
3339

34-
def sewar_initial_check(GT,P):
35-
assert GT.shape == P.shape, "Supplied images have different sizes " + \
36-
str(GT.shape) + " and " + str(P.shape)
37-
if GT.dtype != P.dtype:
38-
msg = "Supplied images have different dtypes " + \
39-
str(GT.dtype) + " and " + str(P.dtype)
40-
_logger.warn(msg)
41-
42-
if len(GT.shape) == 2:
43-
GT = GT[:,:,numpy.newaxis]
44-
P = P[:,:,numpy.newaxis]
45-
46-
return GT.astype(numpy.float64),P.astype(numpy.float64)
47-
4840
class ChartTestTask(TestTask):
4941
def __init__(self, analysis_file_name, id, chart_name, simulation_project=None, name="chart test", **kwargs):
5042
super().__init__(name=name, **kwargs)
@@ -77,8 +69,12 @@ def run_protected(self, keep_charts=True, output_stream=sys.stdout, **kwargs):
7769
if os.path.exists(old_file_name):
7870
new_image = matplotlib.image.imread(new_file_name)
7971
old_image = matplotlib.image.imread(old_file_name)
72+
if old_image.shape != new_image.shape:
73+
return self.task_result_class(self, result="FAIL", reason="Supplied images have different sizes" + str(old_image.shape) + " and " + str(new_image.shape))
8074
metric = sewar_rmse(old_image, new_image)
81-
if metric == 0 or not keep_charts:
75+
if type(metric) == str:
76+
_logger.info(metric)
77+
elif metric == 0 or not keep_charts:
8278
os.remove(new_file_name)
8379
else:
8480
image_diff = numpy.abs(new_image - old_image)
@@ -183,7 +179,10 @@ def run_protected(self, keep_charts=True, **kwargs):
183179
if os.path.exists(old_file_name):
184180
new_image = matplotlib.image.imread(new_file_name)
185181
old_image = matplotlib.image.imread(old_file_name)
186-
metric = sewar_rmse(old_image, new_image)
182+
if old_image.shape != new_image.shape:
183+
metric = 1
184+
else:
185+
metric = sewar_rmse(old_image, new_image)
187186
if metric == 0:
188187
os.remove(new_file_name)
189188
else:

0 commit comments

Comments
 (0)