How to replace the appropriate colors with my own pallette in MATLAB?

送分小仙女□ 提交于 2019-12-12 02:24:24

问题


I am using MATLAB 2015. I want to reduce the image color count. An RGB image will be segmentated using k-means algorithm. Then mean colors will be replaced with the colors I have.

The colors are (10),

black - [255, 255, 255],

yellow - [255, 255, 0],

orange - [255, 128, 0],

white - [255, 255, 255],

pink - [255, 153, 255],

lavender - [120, 102, 255],

brown - [153, 51, 0],

green - [0, 255, 0],

blue - [0, 0, 255],

red - [255, 0, 0].

I have succeeded clustering the image. Clustered images should be replaced with the nearest color. How can I change those colors after clustering?


回答1:


In case you don't succeed in finding a way with MATLAB, you can remap the colours in an image at the command line with ImageMagick which is installed on most Linux distros and is available for OSX and Windows too.

First, you would make a swatch of the colours in your palette. You only need do this once obviously:

convert xc:black           xc:yellow             xc:"rgb(255,128,0)"   \
        xc:white           xc:"rgb(255,153,255)" xc:"rgb(120,102,255)" \
        xc:"rgb(153,51,0)" xc:lime xc:blue       xc:red                \
        +append colormap.png

That looks like this (enlarged):

Now, let's assume you have an image like this colorwheel (colorwheel.png):

and you want to apply your palette (i.e. remap the colours to those in your swatch):

convert colorwheel.png +dither -remap colormap.png result.png



来源:https://stackoverflow.com/questions/38326766/how-to-replace-the-appropriate-colors-with-my-own-pallette-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!