Generating solid color images with python | Kaggle icon

Introduction

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.

Color selection

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.

Creating a solid color image

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.

Output image

lightcyan.png Good color ~

Summary

numpy array convenient! (Nth time)

Recommended Posts

Generating solid color images with python | Kaggle icon
Bordering images with python Part 1
Number recognition in images with Python
Generating multilingual text images using Python
Post multiple Twitter images with python
Animate multiple still images with Python
Load gif images with Python + OpenCV
[Python] Collect images easily with icrawler!
Working with DICOM images in Python
Try to reproduce color film with Python
Amplify images for machine learning with python
Output color characters to pretty with python
Capturing images with Pupil, python and OpenCV
[python, openCV] base64 Face recognition with images
[Python] Read images with OpenCV (for beginners)
Add Gaussian noise to images with python2.7
Importing and exporting GeoTiff images with Python
Read text in images with python OCR
Upload images to Google Drive with Python
Convert PDFs to images in bulk with Python
Color page judgment of scanned image with python
Create a color bar with Python + Qt (PySide)
[Python] Collect images with Icrawler for machine learning [1000 images]
Bulk download images from specific URLs with python
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Automatically paste images into PowerPoint materials with python + α
Bulk download images from specific site URLs with python
Try projective transformation of images using OpenCV with Python
Fill the background with a single color with OpenCV2 + Python
Pretty print json or yaml with color in python
I tried "morphology conversion" of images with Python + OpenCV