Skip to content

xy-gao/instance-dominant-colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

instance-dominant-colors

Extract dominant colors from an instance segment.

Instance segmentstion method: Mask R-CNN with its provided trained COCO model.

Extract dominant colors method: k-means clustering

Example

pizza


Photo by mahyar motebassem on Unsplash

traffic light


Photo by Aleksandr Kotlyar on Unsplash

dog

Installation

Clone this repository

$ cd instance-dominant-colors
$ pip3 install -r requirements.txt

Usage

from instance2color import Instance2Color

inst = Instance2Color(image_file='sample_img/pizza.jpg', class_name='pizza', num_of_color=5)
# available class names are:
# 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']
# model will be downloaded if not exist

print(inst.dominant_colors()) # RGBs and percentages
# [([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')
# visualize pie chart
inst.visualize_instance(output_file='sample_img/pizza_inst.jpg')
# visualize instance segmentation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages