Skip to content

Commit

Permalink
Fixes a bug in ERGAS
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewekhalel committed Jul 30, 2023
1 parent ac76e7b commit 56be355
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
30 changes: 12 additions & 18 deletions sewar/full_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,35 +160,29 @@ def ssim (GT,P,ws=11,K1=0.01,K2=0.03,MAX=None,fltr_specs=None,mode='valid'):
return np.mean(ssims),np.mean(css)


def ergas(GT,P,r=4,ws=8):
def ergas(GT,P,r=0.25):
"""calculates erreur relative globale adimensionnelle de synthese (ergas).
:param GT: first (original) input image.
:param P: second (deformed) input image.
:param r: ratio of high resolution to low resolution (default=4).
:param ws: sliding window size (default = 8).
:param r: ratio of high resolution to low resolution (default=1/4).
:returns: float -- ergas value.
"""
GT,P = _initial_check(GT,P)

rmse_map = None
nb = 1

_,rmse_map = rmse_sw(GT,P,ws)

means_map = uniform_filter(GT,ws)/ws**2
nb = GT.shape[2]

# Avoid division by zero
idx = means_map == 0
means_map[idx] = 1
rmse_map[idx] = 0
GT_means_per_band = np.mean(GT, axis=(0,1))

ergasroot = np.sqrt(np.sum(((rmse_map**2)/(means_map**2)),axis=2)/nb)
ergas_map = 100*r*ergasroot;

s = int(np.round(ws/2))
return np.mean(ergas_map[s:-s,s:-s])
rmse_per_band = np.zeros(nb)
for b in range(nb):
rmse_per_band[b] = rmse(GT[:,:,b],P[:,:,b])

presratio = 100*r
div = (rmse_per_band**2) / (GT_means_per_band**2)
ergasroot = np.sqrt( np.sum(div)/ nb )
return presratio*ergasroot

def _scc_single(GT,P,win,ws):
def _scc_filter(inp, axis, output, mode, cval):
Expand Down
4 changes: 4 additions & 0 deletions sewar/tests/test_sewar.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def test_color(self):
ergas = sewar.ergas(self.read('clr'),self.read('clr'))
self.assertTrue(ergas == 0)

def test_color_noise(self):
ergas = sewar.ergas(self.read('clr'),self.read('clr_noise'))
self.assertTrue(abs(ergas - 10.6068) < self.eps)

def test_gray(self):
ergas = sewar.ergas(self.read('gry'),self.read('gry'))
self.assertTrue(ergas == 0)
Expand Down
14 changes: 10 additions & 4 deletions sewar/tests/test_sewar_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,22 @@ class TestErgasCli(Tester):
def test_color(self):
args = dict(GT = self.path('clr'),
P = self.path('clr'),
metric= 'ergas',
ws = 16)
metric= 'ergas')
ergas = sewar.cli(args)
self.assertTrue(ergas == 0)

def test_color_noise(self):
args = dict(GT = self.path('clr'),
P = self.path('clr_noise'),
metric= 'ergas')
ergas = sewar.cli(args)
print(ergas)
self.assertTrue(abs(ergas - 10.6068) < self.eps)

def test_gray(self):
args = dict(GT = self.path('gry'),
P = self.path('gry'),
metric= 'ergas',
ws = 4)
metric= 'ergas')
ergas = sewar.cli(args)
self.assertTrue(ergas == 0)

Expand Down

0 comments on commit 56be355

Please sign in to comment.