rogermt's picture
Upload 47 files
b48dd06 verified
raw
history blame contribute delete
874 Bytes
#!/usr/bin/env python3
import numpy as np
def tile_transform(phi, out_shape):
a = np.array(phi)
h_out, w_out = out_shape
h_in, w_in = a.shape
reps_h = (h_out + h_in - 1) // h_in
reps_w = (w_out + w_in - 1) // w_in
tiled = np.tile(a, (reps_h, reps_w))
return tiled[:h_out, :w_out]
class ShiftedTile:
def __init__(self, shift=(1,1), factor=3):
self.shift = shift
self.factor = factor
def apply(self, phi):
h,w = phi.shape
tiled = tile_transform(phi, (h*self.factor, w*self.factor))
return np.roll(tiled, shift=self.shift, axis=(0,1))
if __name__ == '__main__':
inp = np.array([[0,7,7],[7,7,7],[0,7,7]])
T = ShiftedTile()
out = T.apply(inp)
out_resized = tile_transform(out, inp.shape) if out.shape != inp.shape else out
print("Changed cells:", int((out_resized != inp).sum()))