Created
May 8, 2019 07:47
-
-
Save ashnair1/de2b47a1332f1ba10800ce566c4e86b0 to your computer and use it in GitHub Desktop.
Comparing size of objects with respect to image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Script for visualising the size comparison between the object and the image to determine accurate anchor sizes | |
""" | |
from PIL import Image | |
import numpy as np | |
img_size = (1024,1024) | |
obj_size = (16,16) | |
img = np.zeros([img_size[0],img_size[1],3],dtype=np.uint8) | |
img.fill(255) # or img[:] = 255 | |
obj = np.zeros([obj_size[0],obj_size[1],3],dtype=np.uint8) | |
obj.fill(0) | |
# Convert from numpy array to PIL image | |
#Image on which we want to paste | |
img = Image.fromarray(np.uint8(img)) | |
#Image which we want to paste | |
obj = Image.fromarray(np.uint8(obj)) | |
img.paste(obj,(50,50)) | |
#Save in the same relative location | |
img.save("{}x{}_on_{}x{}.jpg".format(obj_size[0],obj_size[1],img_size[0],img_size[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment