Skip to content

Instantly share code, notes, and snippets.

@DmitryUlyanov
Last active May 11, 2017 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DmitryUlyanov/f66805e1328fa64ba98645ce24d9dc2e to your computer and use it in GitHub Desktop.
Save DmitryUlyanov/f66805e1328fa64ba98645ce24d9dc2e to your computer and use it in GitHub Desktop.
draws images at given 2d coordinates like T-SNE of MNIST
def imscatter(images, positions):
positions = np.array(positions)
bottoms = positions[:,1] - np.array([im.shape[1]/2.0 for im in images])
tops = bottoms + np.array([im.shape[1] for im in images])
lefts = positions[:,0] - np.array([im.shape[0]/2.0 for im in images])
rigths = lefts + np.array([im.shape[0] for im in images])
most_bottom = np.floor(bottoms.min())
most_top = np.ceil(tops.max())
most_left = np.floor(lefts.min())
most_right = np.ceil(rigths.max())
print most_bottom, most_top , most_left, most_right
scatter_image = np.zeros([most_right - most_left,most_top-most_bottom,3],dtype = imgs[0].dtype)
# shift, now all from zero
positions -= [most_left,most_bottom]
for im,pos in zip(images,positions):
xl = int(pos[0] - im.shape[0]/2)
xr = xl + im.shape[0]
yb = int(pos[1] - im.shape[1]/2)
yt = yb + im.shape[1]
scatter_image[xl:xr,yb:yt,:] = im
return scatter_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment