I created an account to get started with Kaggle and tried to set up my profile. I wanted to unify it with the Twitter and Qiita icons, and when I tried to upload the usual image ... In the center is the text ** Upload Image (min. 400x400) **
The size of the image I always used for the icon is (240x420), so of course reject! It was just a single color image, but it was a delicate size because it was an image that I searched for my favorite color and picked it up appropriately.
Alright, let's write a program to generate a single color image.
I chose the color by referring to the primary color dictionary of here.
As an example, if you click on lightcyan, which is the color of your icon
You will be taken to a page with various numerical data about the color.
This time, we will use rgb (224,255,255)
because we will generate the image in rgb color space.
I made a function that returns an array of monochromatic images with color and image size as arguments.
create_monochromatic_img
def create_monochromatic_img(color, size):
r = color[0] * np.ones((size[1], size[0], 1), dtype=np.uint8)
g = color[1] * np.ones((size[1], size[0], 1), dtype=np.uint8)
b = color[2] * np.ones((size[1], size[0], 1), dtype=np.uint8)
return np.concatenate([r, g, b], axis=2)
Color is lightcyan, when you want to create an image of size 400x400
main
#python3.6.7
#import numpy as np
#import cv2
color = [224, 255, 255] #[r,g,b]
size = [400,400] #[height,width]
img = create_monochromatic_img(color, size)
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
cv2.imwrite('out.png', img)
Do as above.
Good color ~
numpy array convenient! (Nth time)
Recommended Posts