Skip to content

Instantly share code, notes, and snippets.

@ntdat017
Created April 21, 2022 08:55
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 ntdat017/ce3a32af49cc17b4fac59e61e2697d2b to your computer and use it in GitHub Desktop.
Save ntdat017/ce3a32af49cc17b4fac59e61e2697d2b to your computer and use it in GitHub Desktop.
import random
import colorsys
import matplotlib.pyplot as plt
def create_image(w, h, color):
image = np.zeros((w, h, 3), np.uint8)
# Fill image with red color(set each pixel to red)
image[:] = color
return image
# HSL color illustration https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Hsl-hsv_models.svg/1200px-Hsl-hsv_models.svg.png
h,s,l = random.random(), 0.5 + random.random()/2.0, 0.8 + random.random()/5.0
r,g,b = [int(256*i) for i in colorsys.hls_to_rgb(h,l,s)]
color = (r, g, b)
# example
w = h = 100
img = create_image(w, h, color)
plt.imshow(img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment