Using Mask R-CNN and the provided trained model, only the objects in the image are extracted as RGB data. When the RGB data is clustered with K-Means, the object's dominant color .com / gao_gao / items / 26269cd4ae8fdf55e608) can be extracted.
Photo by mahyar motebassem on Unsplash
Photo by Aleksandr Kotlyar on Unsplash
$ git clone https://github.com/xy-gao/instance-dominant-colors.git
$ cd instance-dominant-colors
$ pip3 install -r requirements.txt
from instance2color import Instance2Color
inst = Instance2Color(image_file='sample_img/pizza.jpg', class_name='pizza', num_of_color=5)
#Class that can be specified_name:
# class_names = ['BG', 'person', 'bicycle', 'car', 'motorcycle', 'airplane',
# 'bus', 'train', 'truck', 'boat', 'traffic light',
# 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird',
# 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear',
# 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie',
# 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball',
# 'kite', 'baseball bat', 'baseball glove', 'skateboard',
# 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup',
# 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
# 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza',
# 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed',
# 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote',
# 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster',
# 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors',
# 'teddy bear', 'hair drier', 'toothbrush']
#The trained model is downloaded for the first time
print(inst.dominant_colors()) #Dominant color RGB and proportion
# [([174, 77, 68], 29.52), ([223, 140, 100], 26.31), ([99, 47, 38], 20.08), ([96, 181, 108], 12.91), ([227, 206, 189], 11.18)]
inst.visualize_pie(output_file='sample_img/pizza_pie_chart.jpg')#Draw a pie chart
inst.visualize_instance(output_file='sample_img/pizza_inst.jpg')#You can check where it was targeted