在matlab中排序颜色 [英] sorting colors in matlab

查看:443
本文介绍了在matlab中排序颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在260000 * 3维数组中有不同的RGB值。我要按升序或降序排列这些颜色(不重要是哪一个),以使相似的颜色更接近。什么是最有效的方法来做到这一点?

I have different RGB values in a 260000 * 3 dimension array. I wan to sort these colors in ascending or descending order (it does not matter which) so that similar colors are closer. What's the most efficient way to do this?

推荐答案

示例:



首先, :

Example:

First we start with the regular Jet colormap:

%# sample image mapped to Jet colormap
I = repmat(1:100, 100, 1);
C = jet(100);

figure
subplot(211), imagesc(I), colormap(C)
subplot(212), rgbplot(C)

首先,我们洗牌的颜色。然后,我们尝试恢复原始的颜色分组(我们通过在 HSV 颜色空间中排序根据色调和值):

First we shuffle the colors. Then we try to recover the original grouping of colors (we do this by sorting in the HSV colorspace according to the hue and value):

%# shuffle colors
C = C(randperm(100), :);

%# rearrage according to HSV colorspace
C = rgb2hsv(C);
C = sortrows(C, [-1 -3 2]);  %# sort first by Hue, then by value
C = hsv2rgb(C);

figure
subplot(211), imagesc(I), colormap(C)
subplot(212), rgbplot(C)

这篇关于在matlab中排序颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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