Guest User

Untitled

a guest
May 20th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. >>> image.shape
  2. (800, 600, 3)
  3. >>> chex.shape
  4. (800, 600, 3)
  5. >>> mask.shape
  6. (800, 600)
  7.  
  8. image[mask == 0,...] = chex
  9.  
  10. idx=(mask==0)
  11. image[idx]=chex[idx]
  12.  
  13. image[mask[:] == 0,...] = chex[mask[:] == 0,...]
  14.  
  15. # first create mini-versions of your arrays:
  16. mask = NP.random.random_integers(0, 1, 48).reshape(8, 6)
  17. img = NP.random.random_integers(3, 9, 8*6*3).reshape(8, 6, 3)
  18. chk = NP.ones((8, 6, 3))
  19.  
  20. # all the work done in these two lines
  21. mask = mask[:,:,NP.newaxis]
  22. res = NP.where(mask==0, chk, img)
  23.  
  24. import matplotlib.pyplot as plt
  25. from scipy.ndimage import rotate
  26.  
  27.  
  28. cat = plt.imread('cat.jpeg')
  29. bg = plt.imread('background.jpeg')
  30.  
  31.  
  32. rotcat = rotate(cat, angle=8, reshape=True) ## rotating creates some black edges
  33. height, width, _ = rotcat.shape
  34.  
  35. bgcopy = bg.copy() ## create a copy of the background; paste on copy
  36.  
  37. x, y = 40, 50
  38. bgcopy[x:x+height, y:y+width] = rotcat
  39. plt.imsave('cat-on-bg-mask.jpg', bgcopy)
  40.  
  41. mask_ind = (bgcopy == 0)
  42. bgcopy[mask_ind] = bg[mask_ind]
  43. plt.imsave('cat-on-bg.jpg', bgcopy)
Add Comment
Please, Sign In to add comment