问题
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