Created
September 15, 2022 06:34
-
-
Save fgiobergia/ae90ed5580aeeba16f14f903b9576cdf to your computer and use it in GitHub Desktop.
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
""" | |
Code snippet to generate a scatter plot from a given image (mask). | |
""" | |
from PIL import Image | |
import numpy as np | |
import matplotlib.pyplot as plt | |
im = Image.open("image.png") | |
mask = (np.array(im) > 0).any(axis=2) # masking condition | |
np.random.seed(44) | |
ys, xs = np.nonzero(mask) | |
ndx = np.random.choice(len(xs), size=1500, replace=False) | |
plt.figure(figsize=(max(xs)//100, max(ys)//100)) | |
plt.scatter(xs[ndx], -ys[ndx], s=10, c='#163473') | |
plt.axis("off") | |
plt.savefig("logo.svg", bbox_inches="tight") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment