def STSIM_M(self, im): ss = Steerable(5) M, N = im.shape coeff = ss.buildSCFpyr(im) f = [] # single subband statistics for s in ss.getlist(coeff): s = s.real shiftx = np.roll(s, 1, axis=0) shifty = np.roll(s, 1, axis=1) f.append(np.mean(s)) f.append(np.var(s)) f.append((shiftx * s).mean() / s.var()) f.append((shifty * s).mean() / s.var()) # correlation statistics # across orientations for orients in coeff[1:-1]: for (s1, s2) in list(itertools.combinations(orients, 2)): f.append((s1.real * s2.real).mean()) for orient in range(len(coeff[1])): for height in range(len(coeff) - 3): s1 = coeff[height + 1][orient].real s2 = coeff[height + 2][orient].real s1 = cv2.resize(s1, (0, 0), fx=0.5, fy=0.5) f.append( (s1 * s2).mean() / np.sqrt(s1.var()) / np.sqrt(s2.var())) return np.array(f)
def STSIM_M(self, im): ss = Steerable(5) M, N = im.shape coeff = ss.buildSCFpyr(im) f = [] # single subband statistics for s in ss.getlist(coeff): s = s.real shiftx = np.roll(s,1, axis = 0) shifty = np.roll(s,1, axis = 1) f.append(np.mean(s)) f.append(np.var(s)) f.append((shiftx * s).mean()/s.var()) f.append((shifty * s).mean()/s.var()) # correlation statistics # across orientations for orients in coeff[1:-1]: for (s1, s2) in list(itertools.combinations(orients, 2)): f.append((s1.real*s2.real).mean()) for orient in range(len(coeff[1])): for height in range(len(coeff) - 3): s1 = coeff[height + 1][orient].real s2 = coeff[height + 2][orient].real s1 = cv2.resize(s1, (0,0), fx = 0.5, fy = 0.5) f.append((s1*s2).mean()/np.sqrt(s1.var())/np.sqrt(s2.var())) return np.array(f)
def STSIM(self, im1, im2): assert im1.shape == im2.shape s = Steerable() pyrA = s.getlist(s.buildSCFpyr(im1)) pyrB = s.getlist(s.buildSCFpyr(im2)) stsim = map(self.pooling, pyrA, pyrB) return np.mean(stsim)
def STSIM2(self, im1, im2): assert im1.shape == im2.shape s = Steerable() s_nosub = SteerableNoSub() pyrA = s.getlist(s.buildSCFpyr(im1)) pyrB = s.getlist(s.buildSCFpyr(im2)) stsim2 = map(self.pooling, pyrA, pyrB) # Add cross terms bandsAn = s_nosub.buildSCFpyr(im1) bandsBn = s_nosub.buildSCFpyr(im2) Nor = len(bandsAn[1]) # Accross scale, same orientation for scale in range(2, len(bandsAn) - 1): for orient in range(Nor): im11 = np.abs(bandsAn[scale - 1][orient]) im12 = np.abs(bandsAn[scale][orient]) im21 = np.abs(bandsBn[scale - 1][orient]) im22 = np.abs(bandsBn[scale][orient]) stsim2.append( self.compute_cross_term(im11, im12, im21, im22).mean()) # Accross orientation, same scale for scale in range(1, len(bandsAn) - 1): for orient in range(Nor - 1): im11 = np.abs(bandsAn[scale][orient]) im21 = np.abs(bandsBn[scale][orient]) for orient2 in range(orient + 1, Nor): im13 = np.abs(bandsAn[scale][orient2]) im23 = np.abs(bandsBn[scale][orient2]) stsim2.append( self.compute_cross_term(im11, im13, im21, im23).mean()) return np.mean(stsim2)
def STSIM2(self, im1, im2): assert im1.shape == im2.shape s = Steerable() s_nosub = SteerableNoSub() pyrA = s.getlist(s.buildSCFpyr(im1)) pyrB = s.getlist(s.buildSCFpyr(im2)) stsim2 = map(self.pooling, pyrA, pyrB) # Add cross terms bandsAn = s_nosub.buildSCFpyr(im1) bandsBn = s_nosub.buildSCFpyr(im2) Nor = len(bandsAn[1]) # Accross scale, same orientation for scale in range(2, len(bandsAn) - 1): for orient in range(Nor): im11 = np.abs(bandsAn[scale - 1][orient]) im12 = np.abs(bandsAn[scale][orient]) im21 = np.abs(bandsBn[scale - 1][orient]) im22 = np.abs(bandsBn[scale][orient]) stsim2.append(self.compute_cross_term(im11, im12, im21, im22).mean()) # Accross orientation, same scale for scale in range(1, len(bandsAn) - 1): for orient in range(Nor - 1): im11 = np.abs(bandsAn[scale][orient]) im21 = np.abs(bandsBn[scale][orient]) for orient2 in range(orient + 1, Nor): im13 = np.abs(bandsAn[scale][orient2]) im23 = np.abs(bandsBn[scale][orient2]) stsim2.append(self.compute_cross_term(im11, im13, im21, im23).mean()) return np.mean(stsim2)