Generating Color Image in Python
Today when browsing Zhihu, I came across this interesting package in python where I can generate digital images by creating a matrix of RGB parameters. Here I created a very simple example to generate pure color image.
First install package opencv-python:
pip install opencv-python
Then import the cv2 module and use the imwrite function to create image with specified color.
import numpy as np
def generate_imgage_hex(size, BGR):
return np.ones((size, size, 1)) * \
size = [1080, 1080]
color = "314159"
cv2.imwrite('image.png', generate_imgage_hex(size, color))
We have just created a image with color
#594131 in each pixels.
The openCV package was first released in 2000, and currently supports algorithms related to computer vision and machine learning.