Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3 changes #25

Open
wants to merge 1 commit into
base: publish
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
return ((X*224.0)+112.0)*Xscale, ((Y*224.0)+112.0)*Yscale, ((Z*224.0)+112.0)*Xscale
4 changes: 2 additions & 2 deletions src/VGG16.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions src/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions src/utils/shape_context.py
Original file line number Diff line number Diff line change
@@ -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')


Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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])

Expand All @@ -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
return result
12 changes: 7 additions & 5 deletions src/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, :]
Expand Down