How to control color and brightness for a vector map

조회 수: 8 (최근 30일)
Shang Gao
Shang Gao 2017년 12월 3일
답변: Guillaume 2017년 12월 3일
Hi, I have a vector field with a 400x400 data point. Each point has a vector with a magnitude and direction. What I want to do is to draw a 400x400map. Each pixel's color represents the direction(say rainbow color from red to purple to represent 0 to 360 degree direction) and the brightness of that pixel to represent the magnitude. Now I only know several separate color's representation. I don't know how to continuously tune the color like a rainbow.Also I don't know how to tune the brightness at the same time. Can someone help me with this?

채택된 답변

Guillaume
Guillaume 2017년 12월 3일
First, I would refer you to How The Rainbow Color Map Misleads or Rainbow Color Map (Still) Considered Harmful. Matlab changed their default colour map a while ago probably partly because of this.
From reading the above links it should become obvious that you can't do what you want with a rainbow colour map anyway as the map is a mix of different hues and different brighness.
You could do what you want by switching to the HSV colour space. In that 3 dimensional cylindrical colour space, hue is encoded as a 0-360 angle, exactly as your direction. The value (more or less the brightness) is the 3rd dimension and you could equate that to your vector magnitude. The saturation you could leave constant at maximum.
%demo vector field:
vectordirection = rand(400, 400)*360;
vectormagnitude = rand(400, 400);
imghsv(:, :, 1) = vectordirection / 360; %matlab encodes hue in the range 0-1
imghsv(:, :, 2) = 1; %constant saturation (at maximum)
imghsv(:, :, 3) = vectormagnitude; %needs to be in the range 0-1
imgrgb = hsv2rgb(imghsv);
imshow(imgrgb);
However, points with very low magnitude will more or less look the same: near black, since at low brightness the eye can't really distinguish between colours (See the bottom of the HSV cylinder on the wikipedia page).

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by