Skip to content
This repository was archived by the owner on Jan 2, 2021. It is now read-only.
Open
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
14 changes: 8 additions & 6 deletions enhance.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def match_histograms(self, A, B, rng=(0.0, 255.0), bins=64):
map_Hb = scipy.interpolate.interp1d(Hpb, X, bounds_error=False)
return map_Hb(inv_Ha(A).clip(0.0, 255.0))

def process(self, original):
def process(self, filename, original):
# Snap the image to a shape that's compatible with the generator (2x, 4x)
s = 2 ** max(args.generator_upscale, args.generator_downscale)
by, bx = original.shape[0] % s, original.shape[1] % s
Expand All @@ -620,12 +620,15 @@ def process(self, original):
image = np.pad(original, ((p, p), (p, p), (0, 0)), mode='reflect')
output = np.zeros((original.shape[0] * z, original.shape[1] * z, 3), dtype=np.float32)

tileslist = list(itertools.product(range(0, original.shape[0], s), range(0, original.shape[1], s)))

# Iterate through the tile coordinates and pass them through the network.
for y, x in itertools.product(range(0, original.shape[0], s), range(0, original.shape[1], s)):
for tilenumber, (y, x) in enumerate(tileslist):
print("\r%s (tile %d of %d)" % (filename, tilenumber, len(tileslist)), end='', flush=True)
img = np.transpose(image[y:y+p*2+s,x:x+p*2+s,:] / 255.0 - 0.5, (2, 0, 1))[np.newaxis].astype(np.float32)
*_, repro = self.model.predict(img)
output[y*z:(y+s)*z,x*z:(x+s)*z,:] = np.transpose(repro[0] + 0.5, (1, 2, 0))[p*z:-p*z,p*z:-p*z,:]
print('.', end='', flush=True)
print("\r%s (tile %d of %d)" % (filename, len(tileslist), len(tileslist)), end='\n', flush=True)
output = output.clip(0.0, 1.0) * 255.0

# Match color histograms if the user specified this option.
Expand All @@ -644,9 +647,8 @@ def process(self, original):
else:
enhancer = NeuralEnhancer(loader=False)
for filename in args.files:
print(filename, end=' ')
print(filename, end=' ', flush=True)
img = scipy.ndimage.imread(filename, mode='RGB')
out = enhancer.process(img)
out = enhancer.process(filename, img)
out.save(os.path.splitext(filename)[0]+'_ne%ix.png' % args.zoom)
print(flush=True)
print(ansi.ENDC)