|
28 | 28 |
|
29 | 29 |
|
30 | 30 | 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) |
32 | 38 | return numpy.sqrt(numpy.mean((a.astype(numpy.float64)-b.astype(numpy.float64))**2)) |
33 | 39 |
|
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 | | - |
48 | 40 | class ChartTestTask(TestTask): |
49 | 41 | def __init__(self, analysis_file_name, id, chart_name, simulation_project=None, name="chart test", **kwargs): |
50 | 42 | super().__init__(name=name, **kwargs) |
@@ -77,6 +69,8 @@ def run_protected(self, keep_charts=True, output_stream=sys.stdout, **kwargs): |
77 | 69 | if os.path.exists(old_file_name): |
78 | 70 | new_image = matplotlib.image.imread(new_file_name) |
79 | 71 | 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)) |
80 | 74 | metric = sewar_rmse(old_image, new_image) |
81 | 75 | if metric == 0 or not keep_charts: |
82 | 76 | os.remove(new_file_name) |
@@ -183,7 +177,10 @@ def run_protected(self, keep_charts=True, **kwargs): |
183 | 177 | if os.path.exists(old_file_name): |
184 | 178 | new_image = matplotlib.image.imread(new_file_name) |
185 | 179 | old_image = matplotlib.image.imread(old_file_name) |
186 | | - metric = sewar_rmse(old_image, new_image) |
| 180 | + if old_image.shape != new_image.shape: |
| 181 | + metric = 1 |
| 182 | + else: |
| 183 | + metric = sewar_rmse(old_image, new_image) |
187 | 184 | if metric == 0: |
188 | 185 | os.remove(new_file_name) |
189 | 186 | else: |
|
0 commit comments