将颜色表喷射为灰度 [英] Jet colormap to grayscale

查看:87
本文介绍了将颜色表喷射为灰度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个喷射色图:

,我想知道是否有某种方法可以转换为灰度.我不能使用平均值,因为最大值和最小值变为相同的灰色.或者,如果有某种方法可以转换为其他调色板.

and I would like to know if there's some way to convert to a grayscale. I can't use average because maximum and minimum value goes to the same gray color. Or if there's some way to convert to another color palette.

我在Google上找不到转换它的函数. MATLAB使用了名为rgb2ind的东西,但我想知道公式.

I can't find on Google a function to convert it. MATLAB uses some thing called rgb2ind but I would like to know the formula.

推荐答案

首先让我使用Jet颜色图创建索引图像:

First let me create an indexed image using the Jet colormap:

img = repmat(uint8(0:255), 100, 1);
cmap = jet(256);

imshow(img, 'Colormap',cmap)

使用IND2GRAY进行的直接转换会产生以下结果:

The straightforward conversion using IND2GRAY produces the following:

J = ind2gray(img,cmap);
imshow(J)

如您所说,最小/最大收敛到相同的值.据我了解,您正在寻找将喷射颜色图映射为从深色到浅灰色的线性关系.为此,我们可以使用通过RGB2HSV获得的色相值进行重新排序.功能.将以下内容与原始颜色图进行比较:

As you expressed, the min/max converge to the same value. From what I understood, you are looking to map the jet colormap to linearly go from dark to light shades of gray. For this, we can reorder using the hue value which we get with the RGB2HSV function. Compare the following against the original colormap:

[~,idx] = sortrows(rgb2hsv(cmap), -1);  %# sort by Hue
C = gray(256);
C = C(idx,:);

imshow(img, 'Colormap',C)

这篇关于将颜色表喷射为灰度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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