From 69ef383cac992ee107b782941c2eeb3041039065 Mon Sep 17 00:00:00 2001 From: imransalam Date: Mon, 28 Dec 2020 14:58:09 +0500 Subject: [PATCH] python3 changes --- src/Registration.py | 4 +++- src/VGG16.py | 4 ++-- src/demo.py | 6 +++--- src/utils/shape_context.py | 26 +++++++++++++------------- src/utils/utils.py | 12 +++++++----- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/Registration.py b/src/Registration.py index f11bf80..3cebf49 100755 --- a/src/Registration.py +++ b/src/Registration.py @@ -45,6 +45,8 @@ def register(self, IX, IY): lambd = self.lambd # resize image + + Xscale = 1.0 * np.array(IX.shape[:2]) / self.shape Yscale = 1.0 * np.array(IY.shape[:2]) / self.shape IX = cv2.resize(IX, (self.height, self.width)) @@ -185,4 +187,4 @@ def register(self, IX, IY): itr = itr + 1 print('finish: itr %d, Q %d, tau %d' % (itr, Q, tau)) - return ((X*224.0)+112.0)*Xscale, ((Y*224.0)+112.0)*Yscale, ((Z*224.0)+112.0)*Xscale \ No newline at end of file + return ((X*224.0)+112.0)*Xscale, ((Y*224.0)+112.0)*Yscale, ((Z*224.0)+112.0)*Xscale diff --git a/src/VGG16.py b/src/VGG16.py index 1717e41..4e5f3c5 100755 --- a/src/VGG16.py +++ b/src/VGG16.py @@ -16,8 +16,8 @@ def __init__(self, vgg16_npy_path=None): path = os.path.join(path, "vgg16partial.npy") vgg16_npy_path = path #print(path) - - self.data_dict = np.load(vgg16_npy_path, encoding='latin1').item() + print(vgg16_npy_path) + self.data_dict = np.load(vgg16_npy_path, encoding='latin1', allow_pickle=True).item() #print("npy file loaded") def build(self, bgr): diff --git a/src/demo.py b/src/demo.py index 1c51052..fcabbfb 100755 --- a/src/demo.py +++ b/src/demo.py @@ -5,12 +5,12 @@ import cv2 # designate image path here -IX_path = '../img/1a.jpg' -IY_path = '../img/1b.jpg' +IX_path = './img/1a.jpg' +IY_path = './img/1b.jpg' IX = cv2.imread(IX_path) IY = cv2.imread(IY_path) - +print(IX) #initialize reg = Registration.CNN() #register diff --git a/src/utils/shape_context.py b/src/utils/shape_context.py index 28d321c..4decaf6 100755 --- a/src/utils/shape_context.py +++ b/src/utils/shape_context.py @@ -1,7 +1,7 @@ from numpy import * import math -from utils import pairwise_distance - +#from utils import pairwise_distance +from utils.utils import pairwise_distance seterr(all='ignore') @@ -29,16 +29,16 @@ def __init__(self, nbins_r=5, nbins_theta=12, r_inner=0.1250, r_outer=2.0): def _dist2(self, x, c): result = zeros((N, len(c))) - for i in xrange(N): - for j in xrange(len(c)): + for i in range(N): + for j in range(len(c)): result[i, j] = euclid_distance(x[i], c[j]) return result def _get_angles(self, x): N = len(x) result = zeros((N, N)) - for i in xrange(N): - for j in xrange(N): + for i in range(N): + for j in range(N): result[i, j] = get_angle(x[i], x[j]) return result @@ -60,7 +60,7 @@ def compute(self, X, r=None): r_bin_edges = logspace(log10(self.r_inner), log10(self.r_outer), self.nbins_r) r_array_q = zeros((N, N), dtype=int) - for m in xrange(self.nbins_r): + for m in range(self.nbins_r): r_array_q += (r_array_n < r_bin_edges[m]) fz = r_array_q > 0 @@ -77,9 +77,9 @@ def compute(self, X, r=None): ################################################################################ BH = zeros((N, self.nbins)) - for i in xrange(N): + for i in range(N): sn = zeros((self.nbins_r, self.nbins_theta)) - for j in xrange(N): + for j in range(N): if (fz[i, j]): sn[r_array_q[i, j] - 1, theta_array_q[i, j] - 1] += 1 BH[i] = sn.reshape(self.nbins) @@ -88,7 +88,7 @@ def compute(self, X, r=None): def _cost(self, hi, hj): cost = 0 - for k in xrange(self.nbins): + for k in range(self.nbins): if (hi[k] + hj[k]): cost += ((hi[k] - hj[k]) ** 2) / (hi[k] + hj[k]) @@ -101,10 +101,10 @@ def cost(self, P, Q, qlength=None): if qlength: d = qlength C = zeros((p, p2)) - for i in xrange(p): - for j in xrange(p2): + for i in range(p): + for j in range(p2): C[i, j] = self._cost(Q[j] / d, P[i] / p) return C - return result \ No newline at end of file + return result diff --git a/src/utils/utils.py b/src/utils/utils.py index d94f970..6f4dfe3 100755 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -115,16 +115,18 @@ def checkboard(I1, I2, n=7): assert I1.shape == I2.shape height, width, channels = I1.shape hi, wi = height/n, width/n - outshape = (hi*n, wi*n, channels) + outshape = (int(hi*n), int(wi*n), int(channels)) + out_image = np.zeros(outshape, dtype='uint8') for i in range(n): - h = hi * i - h1 = h + hi + h = int(hi * i) + h1 = int(h + hi) for j in range(n): - w = wi * j - w1 = w + wi + w = int(wi * j) + w1 = int(w + wi) if (i-j)%2 == 0: + out_image[h:h1, w:w1, :] = I1[h:h1, w:w1, :] else: out_image[h:h1, w:w1, :] = I2[h:h1, w:w1, :]