How can I highlight a region on the image(python)?

I need to highlight a certain area of the image.
This code displays the name of the color of the image:

from PIL import Image
import webcolors

def get_main_color():
 img = Image.open("image.jpg")
 colors = img.getcolors(1920 * 1920) 
 max_occurence, most_present = 0, 0
try:
 for c in colors:
 if c[0] > max_occurence:
 (max_occurence, most_present) = c
 return most_present
 except TypeError:
 raise Exception("more colours")
 # function for determining the color
 # function for translation of the 3 numbers in the name of the color
def closest_colour(requested_colour):
 min_colours = {}
 for key, name in webcolors.css3_hex_to_names.items():
 r_c, g_c, b_c = webcolors.hex_to_rgb(key)
 rd = (r_c - requested_colour[0]) ** 2
 gd = (g_c - requested_colour[1]) ** 2
 bd = (b_c - requested_colour[2]) ** 2
 min_colours[(rd + gd + bd)] = name
 min_colours return[min(min_colours.keys())]

def get_colour_name(requested_colour):
try:
 closest_name = actual_name = webcolors.rgb_to_name(requested_colour)
 except ValueError:
 closest_name = closest_colour(requested_colour)
 actual_name = None
 return actual_name, closest_name

requested_colour = ((get_main_color()))
actual_name, closest_name = get_colour_name(requested_colour)

print ("the name of the color normal:", actual_name, " Another name colors:", closest_name)
March 19th 20 at 08:39
0 answer

Find more questions by tags ImagesPython