如何在MATLAB中用我自己的调色板替换适当的颜色? [英] How to replace the appropriate colors with my own pallette in MATLAB?

查看:780
本文介绍了如何在MATLAB中用我自己的调色板替换适当的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MATLAB2015.我想减少图像颜色数量. RGB图像将使用k-means算法进行分割.然后,平均颜色将替换为我拥有的颜色.

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.

颜色是(10),

黑色-[255,255,255],

black - [255, 255, 255],

黄色-[255,255,0],

yellow - [255, 255, 0],

橙色-[255,128,0],

orange - [255, 128, 0],

白色-[255,255,255],

white - [255, 255, 255],

粉红色-[255,153,255],

pink - [255, 153, 255],

薰衣草-[120,102,255],

lavender - [120, 102, 255],

棕色-[153,51,0],

brown - [153, 51, 0],

绿色-[0,255,0],

green - [0, 255, 0],

蓝色-[0,0,255],

blue - [0, 0, 255],

红色-[255,0,0].

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?

推荐答案

如果您无法成功使用MATLAB找到方法,则可以使用大多数安装的ImageMagick在命令行上重新映射图像中的颜色. Linux发行版,也可用于OSX和Windows.

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):

现在,假设您有一个像这样的色轮(colorwheel.png):

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

这篇关于如何在MATLAB中用我自己的调色板替换适当的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆