Opencv: How to Draw Palette

code implementation

# -*- coding:utf-8 -*-
import cv2
import numpy as np


r_range = 255

image_wh = 530
center_xy = image_wh // 2
image = np.zeros((image_wh, image_wh, 3), dtype=np.uint8)

for x in range(image_wh):
    for y in range(image_wh):
        # whether xy is inside the circle
        if (x - center_xy) ** 2 + (y - center_xy) ** 2 <= r_range ** 2:
            r = np.sqrt((x - center_xy) ** 2 + (y - center_xy) ** 2)
            theta = np.rad2deg(np.arctan2((y - center_xy), (x - center_xy)))
            theta += 180
            # [int(theta // 2), int(r), 255] hsv
            bgr = cv2.cvtColor(np.array([[[int(theta // 2), int(r), 255]]], dtype=np.uint8), cv2.COLOR_HSV2BGR)
            color = tuple([int(x) for x in bgr[0][0]])
            image[x, y] = color

cv2.namedWindow('img', 0)
cv2.imshow('img', image)
cv2.waitKey()

Effect display

Read More: