Image Color detection & Analysis with K-Means Clustering using scikit-learn & OpenCV | #pyGuru

preview_player
Показать описание
In this tutorial, we will learn how to create a program that can detect colors and then calculate the weights of the colors in an image. This will be a fun and straightforward machine learning based computer vision project, where we will use Scikit-learn and OpenCV as our main modules.

The tutorial is divided in 3 parts:
* What is K-Means Clustering
* K-Means Clustering algorithm with example
* Applying K-MEANS on image to cluster most dominant colors in the image

In this tutorial we will be using 5 libraries that are listed as following: OpenCV, Scikit-learn, NumPy, Matplotlib and Collections.

You can install them using pip, by this command

pip install opencv-python scikit-learn numpy matplotlib

Here first we will read the image and then we are using k-Means to cluster the top colors. Inside the function we are passing the value of how many clusters do we want to divide. After clustering we predict the colors that weigh the most — meaning getting the most area on the image.

************************

Scikit-learn is a well-known artificial intelligence and machine learning module. And OpenCV is a must-have computer vision module. OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and accelerate machine perception in commercial products.

#python #machinelearning #opencv #ml #kmeans #clustering #imagesegmentation #scikitlearn #colordetection #imagecolor
#pythonguru python guru
Рекомендации по теме
Комментарии
Автор

Hi, thanks for sharing! A quick question is here. After I download analysis pie chart image, it's still in black and gry color. I'm not sure what's going on. My code is as same as yours. Kindly let me know any idea about it! Thanks!

pin-chiachou
Автор

I am working on something like this but I need a histogram plotted for my image. Also i have only 4 major colors(CMYK) and a spectrum of the same pixelated. SO how do I change or can give the rewritten code for plotting a histogram. Also I need a histogram like color C will be represented as -90° M as 0° and Y as +90° and K is not to be plotted in the graph.

yashasshivakumar
Автор

When I execute this code, sometimes it gives some different values than before result for the same picture. Why does it change even if the picture still same ?

adsoyad-sorj
Автор

Great tutorial! Thanks!
Can you make RGB values also appearing in the final graph?

bbnn
Автор

I just want to convert hexa decimal values into actual Color Name ... How could I do this

mayankmaurya
Автор

In cell 18, you wrote ...cvtColor(img, ... ) . Should it be raw img or it is true?

adsoyad-sorj
visit shbcf.ru