Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> image.shape
- (800, 600, 3)
- >>> chex.shape
- (800, 600, 3)
- >>> mask.shape
- (800, 600)
- image[mask == 0,...] = chex
- idx=(mask==0)
- image[idx]=chex[idx]
- image[mask[:] == 0,...] = chex[mask[:] == 0,...]
- # first create mini-versions of your arrays:
- mask = NP.random.random_integers(0, 1, 48).reshape(8, 6)
- img = NP.random.random_integers(3, 9, 8*6*3).reshape(8, 6, 3)
- chk = NP.ones((8, 6, 3))
- # all the work done in these two lines
- mask = mask[:,:,NP.newaxis]
- res = NP.where(mask==0, chk, img)
- import matplotlib.pyplot as plt
- from scipy.ndimage import rotate
- cat = plt.imread('cat.jpeg')
- bg = plt.imread('background.jpeg')
- rotcat = rotate(cat, angle=8, reshape=True) ## rotating creates some black edges
- height, width, _ = rotcat.shape
- bgcopy = bg.copy() ## create a copy of the background; paste on copy
- x, y = 40, 50
- bgcopy[x:x+height, y:y+width] = rotcat
- plt.imsave('cat-on-bg-mask.jpg', bgcopy)
- mask_ind = (bgcopy == 0)
- bgcopy[mask_ind] = bg[mask_ind]
- plt.imsave('cat-on-bg.jpg', bgcopy)
Add Comment
Please, Sign In to add comment