|
13 | 13 | import logging
|
14 | 14 | import matplotlib
|
15 | 15 | import numpy
|
16 |
| -import sewar |
| 16 | +import importlib.util |
17 | 17 |
|
18 | 18 | import omnetpp
|
19 | 19 | import omnetpp.scave
|
|
26 | 26 |
|
27 | 27 | _logger = logging.getLogger(__name__)
|
28 | 28 |
|
| 29 | + |
| 30 | +def sewar_rmse(a, b): |
| 31 | + a,b = sewar_initial_check(a,b) |
| 32 | + return numpy.sqrt(numpy.mean((a.astype(numpy.float64)-b.astype(numpy.float64))**2)) |
| 33 | + |
| 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 | + |
29 | 48 | class ChartTestTask(TestTask):
|
30 | 49 | def __init__(self, analysis_file_name, id, chart_name, simulation_project=None, name="chart test", **kwargs):
|
31 | 50 | super().__init__(name=name, **kwargs)
|
@@ -58,7 +77,7 @@ def run_protected(self, keep_charts=True, output_stream=sys.stdout, **kwargs):
|
58 | 77 | if os.path.exists(old_file_name):
|
59 | 78 | new_image = matplotlib.image.imread(new_file_name)
|
60 | 79 | old_image = matplotlib.image.imread(old_file_name)
|
61 |
| - metric = sewar.rmse(old_image, new_image) |
| 80 | + metric = sewar_rmse(old_image, new_image) |
62 | 81 | if metric == 0 or not keep_charts:
|
63 | 82 | os.remove(new_file_name)
|
64 | 83 | else:
|
@@ -164,7 +183,7 @@ def run_protected(self, keep_charts=True, **kwargs):
|
164 | 183 | if os.path.exists(old_file_name):
|
165 | 184 | new_image = matplotlib.image.imread(new_file_name)
|
166 | 185 | old_image = matplotlib.image.imread(old_file_name)
|
167 |
| - metric = sewar.rmse(old_image, new_image) |
| 186 | + metric = sewar_rmse(old_image, new_image) |
168 | 187 | if metric == 0:
|
169 | 188 | os.remove(new_file_name)
|
170 | 189 | else:
|
|
0 commit comments