Skip to content

Commit

Permalink
python: copied relevant sewar functions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgeorge309 committed Sep 25, 2024
1 parent d7a672f commit c1daa45
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions python/inet/test/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging
import matplotlib
import numpy
import sewar
import importlib.util

import omnetpp
import omnetpp.scave
Expand All @@ -26,6 +26,25 @@

_logger = logging.getLogger(__name__)


def sewar_rmse(a, b):
a,b = sewar_initial_check(a,b)
return numpy.sqrt(numpy.mean((a.astype(numpy.float64)-b.astype(numpy.float64))**2))

def sewar_initial_check(GT,P):
assert GT.shape == P.shape, "Supplied images have different sizes " + \
str(GT.shape) + " and " + str(P.shape)
if GT.dtype != P.dtype:
msg = "Supplied images have different dtypes " + \
str(GT.dtype) + " and " + str(P.dtype)
_logger.warn(msg)

if len(GT.shape) == 2:
GT = GT[:,:,numpy.newaxis]
P = P[:,:,numpy.newaxis]

return GT.astype(numpy.float64),P.astype(numpy.float64)

class ChartTestTask(TestTask):
def __init__(self, analysis_file_name, id, chart_name, simulation_project=None, name="chart test", **kwargs):
super().__init__(name=name, **kwargs)
Expand Down Expand Up @@ -58,7 +77,7 @@ def run_protected(self, keep_charts=True, output_stream=sys.stdout, **kwargs):
if os.path.exists(old_file_name):
new_image = matplotlib.image.imread(new_file_name)
old_image = matplotlib.image.imread(old_file_name)
metric = sewar.rmse(old_image, new_image)
metric = sewar_rmse(old_image, new_image)
if metric == 0 or not keep_charts:
os.remove(new_file_name)
else:
Expand Down Expand Up @@ -164,7 +183,7 @@ def run_protected(self, keep_charts=True, **kwargs):
if os.path.exists(old_file_name):
new_image = matplotlib.image.imread(new_file_name)
old_image = matplotlib.image.imread(old_file_name)
metric = sewar.rmse(old_image, new_image)
metric = sewar_rmse(old_image, new_image)
if metric == 0:
os.remove(new_file_name)
else:
Expand Down

0 comments on commit c1daa45

Please sign in to comment.