Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Creating a Simple Image
You do not always need to load an image from disk. Creating images programmatically helps you test algorithms and understand how pixel data works.
8 min•By Priygop Team•Updated 2026
Creating Images with NumPy
Creating Images with NumPy
import cv2
import numpy as np
# Create a black image (all zeros): 300 tall, 400 wide, 3 channels
black = np.zeros((300, 400, 3), dtype=np.uint8)
print("Black image shape:", black.shape)
# Create a white image (all 255)
white = np.full((300, 400, 3), 255, dtype=np.uint8)
# Create a solid colour image (orange background)
orange = np.zeros((300, 400, 3), dtype=np.uint8)
orange[:] = [0, 165, 255] # BGR: Orange
# Create a gradient image (brightness increases left to right)
gradient = np.zeros((300, 400), dtype=np.uint8)
for col in range(400):
gradient[:, col] = int(col / 399 * 255)
# Create a checkerboard pattern
checker = np.zeros((300, 400, 3), dtype=np.uint8)
square_size = 50
for row in range(300):
for col in range(400):
if (row // square_size + col // square_size) % 2 == 0:
checker[row, col] = [255, 255, 255]
# Save the results
cv2.imwrite("black.png", black)
cv2.imwrite("gradient.png", gradient)
cv2.imwrite("checkerboard.png", checker)
print("All test images created and saved")Diagram
Loading diagram…
Machine Learning follows a structured pipeline from data to deployment