Extract the color of the object in the image with Mask R-CNN and K-Means clustering

GitHub repository

Overview

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.

Example

Pizza


Photo by mahyar motebassem on Unsplash


Traffic light


Photo by Aleksandr Kotlyar on Unsplash


Dog

How to use

$ 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

Recommended Posts

Extract the color of the object in the image with Mask R-CNN and K-Means clustering
Extract dominant color of image by k-means clustering
Mask RCNN Object Measurement Package (Measurement of object diameter with Mask RCNN)
Extract the table of image files with OneDrive & Python
The story of downgrading the version of tensorflow in the demo of Mask R-CNN.
The meaning of ".object" in Django
Coursera Machine Learning Challenges in Python: ex7-1 (Image compression with K-means clustering)
Change the saturation and brightness of color specifications like # ff000 in python 2.5
Read the graph image with OpenCV and get the coordinates of the final point of the graph
Open an Excel file in Python and color the map of Japan
Text mining: Probability density distribution on the hypersphere and text clustering in KMeans
Be careful of the type when making an image mask with Numpy
Try to separate the background and moving object of the video with OpenCV
Function to extract the maximum and minimum values ​​in a slice with Go
Learn the trends of feature words in texts with Jubatus and categorize input texts
Color page judgment of scanned image with python
[Automation] Extract the table in PDF with Python
Change the color of Fabric errors and warnings
Determine the numbers in the image taken with the webcam
Detect folders with the same image in ImageHash
ROS Lecture 119 Correct the color of the camera image
[Python] Change the text color and background color of a specific keyword in print output
Extract images and tables from pdf with python to reduce the burden of reporting
I tried to extract the text in the image file using Tesseract of the OCR engine
[Note] How to write QR code and description in the same image with python
I just wanted to extract the data of the desired date and time with Django
Supervised learning of mnist in the fully connected layer, clustering and evaluating the final stage
Extract and list personal names and place names in the text
Collaborative filtering with principal component analysis and K-means clustering
[Python] Get the numbers in the graph image with OCR
Visualize the range of interpolation and extrapolation with python
Convert the image in .zip to PDF with Python
POST the image with json and receive it with flask
Extract the maximum value with pandas and change that value
Extract the band information of raster data with python
A server that returns the number of people in front of the camera with bottle.py and OpenCV
Return the image data with Flask of Python and draw it to the canvas element of HTML
Extract image color (RGB)
I tried to find the entropy of the image with python
Try scraping the data of COVID-19 in Tokyo with Python
I tried "gamma correction" of the image with Python + OpenCV
How to find the optimal number of clusters in k-means
Maya | Find out the number of polygons in the selected object
Calculate the square root of 2 in millions of digits with python
Print the name of the object directly under the object specified in Blender
See the power of speeding up with NumPy and SciPy
Detect objects of a specific color and size with Python
[Homology] Count the number of holes in data with Python
Read the VTK file and display the color map with jupyter.
Extract array elements and indexes in descending order with numpy
Similar face image detection using face recognition and PCA and K-means clustering
[Tips] Problems and solutions in the development of python + kivy
Find the average / standard deviation of the brightness values in the image
Handling of HSV color space lower and upper in OpenCV
Image analysis with Object Detection API to try in 1 hour
Play with the password mechanism of GitHub Webhook and Python
Try to extract the features of the sensor data with CNN
Real-time classification of multiple objects in the camera image with deep learning of Raspberry Pi 3 B + & PyTorch