Color quantization with Python
The aim of color clustering is to produce a small set of representative colors which captures the color properties of an image. Using the small set of color found by the clustering, a quantization process can be applied to the image to find a new version of the image that has been "simplified," both in colors and shapes.
In this post we will see how to use the K-Means algorithm to perform. color clustering and how to apply the quantization. Let's see the code:
from numpy import reshape,uint8,flipud
from scipy.cluster.vq import kmeans,vq
img = imread('clearsky.jpg')
# reshaping the pixels matrix
pixel = reshape(img,(img.shape[0]*img.shape[1],3))
# performing the clustering
centroids,_ = kmeans(pixel,6) # six colors will be found
# quantization
qnt,_ = vq(pixel,centroids)
# reshaping the result of the quantization
centers_idx = reshape(qnt,(img.shape[0],img.shape[1]))
clustered = centroids[centers_idx]
figure(1)
subplot(211)
imshow(flipud(img))
subplot(212)
imshow(flipud(clustered))
show()
In this post we will see how to use the K-Means algorithm to perform. color clustering and how to apply the quantization. Let's see the code:
CODE:
from pylab import imread,imshow,figure,show,subplotfrom numpy import reshape,uint8,flipud
from scipy.cluster.vq import kmeans,vq
img = imread('clearsky.jpg')
# reshaping the pixels matrix
pixel = reshape(img,(img.shape[0]*img.shape[1],3))
# performing the clustering
centroids,_ = kmeans(pixel,6) # six colors will be found
# quantization
qnt,_ = vq(pixel,centroids)
# reshaping the result of the quantization
centers_idx = reshape(qnt,(img.shape[0],img.shape[1]))
clustered = centroids[centers_idx]
figure(1)
subplot(211)
imshow(flipud(img))
subplot(212)
imshow(flipud(clustered))
show()
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-734950/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Product Quantization
- color the python console textPython
- LEARNED STEP SIZE QUANTIZATION論文復現
- MODEL COMPRESSION VIA DISTILLATION AND QUANTIZATION翻譯
- putty color
- ACM Color the fenceACM
- SCSS Color 型別CSS型別
- CSS background-colorCSS
- CSS text-fill-colorCSS
- Flutter之Color物件(譯)Flutter物件
- How to change the background color for PyCharmPyCharm
- Unity-設定colorUnity
- F. Color Rows and Columns
- 使用uview元件報錯border-color: $u-border-color!important報錯View元件Import
- HTML input color 拾色器HTML
- CSS-COLOR樣式(轉)CSS
- text-decoration與color屬性
- CSS3 text-fill-colorCSSS3
- CSS 字型新玩法之 Color FontCSS
- Color Wheel for Mac數字色輪Mac
- Color Wheel for Mac (數字色輪)Mac
- css border-color屬性用法CSS
- react-color庫的簡單使用React
- Color UI for Mac(顏色選擇器)UIMac
- 【AGC025B】RGB ColorGC
- CSS-背景顏色|background-colorCSS
- AndroidStudio3.3以上color取色Android
- ghd online employed on color treated hairAI
- 【論文考古】量化SGD QSGD: Communication-Efficient SGD via Gradient Quantization and EncodingEncoding
- win10系統hd color模式有什麼用_win10系統hd color模式使用教程Win10模式
- Android Color 判斷色值小結Android
- Linux下無法執行Color pickerLinux
- 【Leetcode】800. Similar RGB ColorLeetCodeMILA
- CSS color-scheme 和夜間模式CSSScheme模式
- 資料夾設計工具:Color Folder for MacMac
- eclipse安裝color theme外掛Eclipse
- 小米手錶Color與華米手錶GTR哪個好?小米Color與華米GTR手錶區別對比
- ncurses關於顏色系統:start_color(),has_colors(),init_pair(),color_content(),pait_content()AI