Created
April 21, 2022 08:55
-
-
Save ntdat017/ce3a32af49cc17b4fac59e61e2697d2b 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
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