根据两个变量创建具有2D颜色图的绘图 [英] Create a plot with a 2D colourmap depending on two variables

查看:300
本文介绍了根据两个变量创建具有2D颜色图的绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示图片(例如



在MATLAB中有一个选项,一个额外的工具箱?



如果不是,可以手动完成?我想通过将从第一个值给出的灰度图像覆盖在由第二个值给出的色彩图像上,可以实现类似的效果。

解决方案

在你的2D色彩映射中,你实际上是使用HSV颜色空间。



基本上,x轴是色相,Y轴是饱和度。如果其正确缩放,您可以将任何值转换为此空间。如果你确保缩放 [0-1] 间隔中的第3和第4列,你可以轻松地做

  colorRGB = hsv2rgb([val3,val4,0.5]); 

如果对每个像素执行此操作,则会得到所需的图像。



我给出了一个关于HSV如何工作的扩展说明这里


I want to display an image (e.g.imshow) and use a colormap to represent the values of my data points.

However, colormap only gives the option to be dependent on a single variable, but I want a "2D colormap" which depends on two variables.

For example I have a simple image 2x2 pixels:

img = [

1 1 5 6;

1 2 8 7;

2 1 4 3;

2 2 15 3]

Here the first two values of each row are the coordinates, the other two are the values describing the pixel (call them x and y).

When displaying the image I want to use a 2D colormap. For example something like this, which picks a colour depending on both variables (x and y):

Is there an option in MATLAB do to this, possibly in one of the extra toolboxes?

If not can this be done manually? I was thinking by overlaying a grey scale image given from the first value over a colormap image given by the second value a similar effect could be achieved.

解决方案

In your 2D colormap you are actually using the HSV color space.

Basically, your x axis is Hue, and Y axis is Saturation. You can convert any value into this space if its properly scaled. If you make sure that you scale your 3rd and 4rd column in the [0-1] interval you can easily do

colorRGB=hsv2rgb([val3,val4,0.5]);

If you perform this operation for each pixel, you'll get the image you want.

I gave a extended explanation of how HSV works here

这篇关于根据两个变量创建具有2D颜色图的绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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