Applying a color for each pair of spherical angles through the hue and lightness parameters
6 次查看(过去 30 天)
显示 更早的评论
Hello eveyone
I have characterized which is the the polar and azimuthal angles of a vector representation in each point of a 2D plane. Given that the modulus of each vector is constant thorugh all the system, to plot the information, I would like to use some kind of spherical color representation like this
with the hue represented with some color palette similar to the second or third ones depicted by @DGM in this post How can I plot circular colormap for 0-24 hour phase? Ideally, I would need also that depending on the polar angle, the lightness change from white to black, like in the image above. I have done in the past a question in the same like Creation of a 2D colormap to represent simultaneously information about the polar and azimuthal angles, but I still haven't been able to find a way to do it. Any ideas?
2 个评论
Image Analyst
2023-10-17
It's not clear to me exactly what you want -- a gamut visualization, an image of yours with some colormap applied, an Nx3 colormap matrix, or something else. So, I have no ideas other than those that may possibly be what you want. Maybe youi want colorcloud - who knows?
采纳的回答
DGM
2023-10-18
编辑:DGM
2023-10-18
Rereading the question, I take it that the 3D representation is just an example, not necessarily a goal. Given that the vector magnitudes are constant, this can be reduced to a 2D map.
I'm going to do this example using MIMT tools, since MATLAB doesn't have tools for any of these models other than HSV.
% setup
azrange = [0 2*pi];
elrange = [-pi/2 pi/2];
colormodel = 'huslp'; % 'hsv','hsl','hsyp','huslp'
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% constructing some fake az,el data
sz = [500 700];
rng(44524) % just for demo consistency with random test data
%AZ = radgrad(sz,[0.25 0.25],0.75,[0; 1],'double'); % radial gradients
AZ = imresize(perlin(round(sz/10)),sz); % or low-freq random noise
AZ = imrescale(AZ,imrange(AZ),azrange);
%EL = radgrad(sz,[0.75 0.75],0.75,[0; 1],'double');
EL = imresize(perlin(round(sz/10)),sz);
EL = imrescale(EL,imrange(EL),elrange);
% constructing a color image representing the az,el data
% assuming all angles have been wrapped to the appropriate intervals
H = imrescale(AZ,azrange,[0 360]); % this could also be done with rescale()
L = imrescale(EL,elrange,[0 1]);
S = ones(sz); % 100% saturation
% assemble the RGB image using some normalized color model
switch lower(colormodel)
case 'hsv'
azelpict = hsv2rgb(cat(3,H/360,S,L)); % base MATLAB
case 'hsl'
azelpict = hsl2rgb(cat(3,H,S,L)); % MIMT only (or other FEX tools)
case 'hsyp'
azelpict = hsy2rgb(cat(3,H,S,L),'pastel'); % MIMT only
case 'huslp'
azelpict = husl2rgb(cat(3,H,S*100,L*100),'labp'); % MIMT only
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% constructing a reference image to replace the colorbar
N = 256;
cbaz = linspace(azrange(1),azrange(2),N);
cbel = linspace(elrange(1),elrange(2),N);
[cbaz cbel] = meshgrid(cbaz,cbel);
% assuming all angles have been wrapped to the appropriate intervals
H = imrescale(cbaz,azrange,[0 360]);
L = imrescale(cbel,elrange,[0 1]);
S = ones(size(cbaz)); % 100% saturation
% assemble the RGB image
switch lower(colormodel)
case 'hsv'
cbpict = hsv2rgb(cat(3,H/360,S,L)); % base MATLAB
case 'hsl'
cbpict = hsl2rgb(cat(3,H,S,L)); % MIMT only (or other FEX tools)
case 'hsyp'
cbpict = hsy2rgb(cat(3,H,S,L),'pastel'); % MIMT only
case 'huslp'
cbpict = husl2rgb(cat(3,H,S*100,L*100),'labp'); % MIMT only
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% display the things
subplot(1,2,1)
image(azelpict)
axis('equal','tight')
title('My Data')
subplot(1,2,2)
image(cbpict,'xdata',azrange/pi,'ydata',elrange/pi)
axis('square','tight')
set(gca,'ydir','normal')
xlabel('Azimuth (\pi rad)')
ylabel('Elevation (\pi rad)')
These are the figures showing the same random data represented using HSV, HSL, HSYp, and HuSLpab.
It's up to you to decide what you think is most readable in your application. The poor uniformity of HSV/HSL leads to a strong perceived banding effect in smooth data. HuSLp inherits the uniformity of LAB, but its limited chroma range leads to reduced distinctness. This tradeoff is similar to part of the argument often used in favor of rainbow colormaps in 1D colormapping contexts (e.g. jet() vs parula()). HSYp is something in-between (chroma-normalized YPbPr). It has more chroma range than HuSLpab. Nobody would claim it to be uniform, but it's more so than HSV/HSL.
If, for the purpose of readability, it's desired to discretize/quantize the mapping process (i.e. so that there are fewer distinct colors in the 2D map), that may also be an option. I'll leave that for further discussion if needed.
This answer may also work (using a pregenerated arbitrary 2D colormap)
Tangentially related:
5 个评论
Image Analyst
2023-11-29
@Richard Wood in addition to what Walter just said (link to Perlin noise), you might try my attached demo, based on Prof. Peter Kovesi's noiseonf.m code, that makes cloud-like images with 1/f noise.
DGM
2023-11-29
Walter already linked to the tools I used. The use of perlin() was just for demonstration. It was a cheap way to make pseudodata that was formed of cloudlike blobs as in your other posts. If instead we used overlaid radial gradients, it might highlight different aspects of the differences between the color models.
AZ = radgrad(sz,[1 0],1,[0; 1],'double'); % radial gradients
% ...
EL = radgrad(sz,[1 1],1,[0; 1],'double');
% ...
For smooth colormaps:
For quantized maps:
... and yes, radgrad() is also from MIMT.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!