Create a plot with a 2D colourmap depending on two

2019-07-26 03:39发布

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

enter image description here

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.

1条回答
可以哭但决不认输i
2楼-- · 2019-07-26 04:10

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

查看更多
登录 后发表回答