Skip to content

Instantly share code, notes, and snippets.

@chadcooper
Last active December 24, 2015 08:29
Show Gist options
  • Save chadcooper/6770725 to your computer and use it in GitHub Desktop.
Save chadcooper/6770725 to your computer and use it in GitHub Desktop.
Quick and dirty copy/paste of an image onto a larger square.
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
input_img = plt.imread("/home/chad/Projects/corona/leaflet/ds1105-2235df023_23_b_resize.tif")
x = input_img.shape[1]
y = input_img.shape[0]
c = x/2
y1 = c - (y/2)
y2 = c + (y/2)
print x, y, c, y1, y2
my_cm = matplotlib.cm.get_cmap("gray")
im_0 = np.zeros((max(x, y), max(x, y)), dtype=input_img.dtype)
im_0[y1:2341] = input_img
im_0_flip = np.flipud(im_0)
plt.imsave("trial.tif", im_0_flip, cmap=my_cm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment