How to draw a CIELAB color chart?

105 Ansichten (letzte 30 Tage)
Saw
Saw am 22 Mär. 2019
Bearbeitet: DGM am 14 Mai 2023
Dear Matlab community,
I am new to Matlab. Would like to ask for help from Matlab experts.
I would like to draw a circular CIELAB color chart (as below) and mark my data points on it. Is it possible to do so in Matlab, and how?
lab-color-space (1).png
Thank you!
  1 Kommentar
Joseph
Joseph am 9 Mai 2023
Hi,
I am also looking for this EXACT answer. Does anyone have a suggestion?

Melden Sie sich an, um zu kommentieren.

Antworten (3)

DGM
DGM am 14 Mai 2023
Bearbeitet: DGM am 14 Mai 2023
I would argue that a "color wheel" is inappropriate for the task, and in the effort to use it, the example given misrepresents multiple aspects of the thing it's illustrating.
Drawing gamut slices
Illustrating the circular inscribed region
To preface, I'm going to be focused on the representation of colors in sRGB and where the sRGB gamut lies in LAB. It's arguable that illustrating this constraint adds confusion, as what we're trying to illustrate is the expanse of LAB, not the subset that is sRGB. I justify this on the fact that we're going to do so by representing those colors in RGB, and the RGB space we'll likely be using is sRGB.
When projected into LAB, the sRGB gamut is not a circle or a cylinder, so if you're representing it as a cylinder, what exactly are you representing? Are you representing the colors within an neutral-centered inscribed circular region? If so, you can represent the uniformity and color distribution accurately, but you're discarding representable colors and you aren't representing the gamut extents. On the other hand, are you normalizing chroma to make a non-circular region appear circular? If so, you can draw a nice circle that covers the gamut extents, but now you're grossly misrepresenting the color distribution, and the axes labels are explicitly wrong, because what's being illustrated is not chroma.
Back to the specific example at hand. So which of those two ways does the given diagram represent chroma? The answer is neither. It's neither normalized, nor is it a uniform inscribed region. The pixels around the periphery which are ostensibly at C = 100 are somewhere in the chroma range of 34 to 92. It's hard to get less accurate than that.
The given diagram includes an L scale on the side, but there is no reference mark or anything that tells us what L these colors are. It's just a completely useless ruler. What's worse is that the illustrated colors are not in a plane of constant L anyway. They span a range from about 27 to 93.
What about H? It's hard to mess that up, right? While the hue angles are approximately as expected, they're still variably offset (by as much as ~30 degrees), and the progression isn't even monotonic.
So how'd it get so messed up? There's two steps involved in that process. First, come up with a bad idea that forces you to misrepresent the information you're trying to communicate. Second, in the process of executing the bad idea, get lost in all the various compromises that are required and let data truncation make things worse. I believe that the intent was to draw the diagram with normalized chroma, but the calculations wound up pushing things out of gamut and the consequences of naive truncation left us with colors that have moved such that they no longer represent a plane of constant L or a linear H sweep.
Let's back up for a moment. Using the example from the first link, let's draw the colors from the L=50 plane. The image extents cover A,B = [-110 110], so the neutral axis is in the center. Disregarding the addition of a circular mask and some polar grid lines and labels, this would be our "color wheel".
You might notice some odd banding artifacts in the image that seem to surround a region in the middle of the image. These are local changes in the gradient that are caused by truncation. While everything in this range of A,B are valid colors in LAB, they're not all representable in sRGB. If we were to shade the region that's out of gamut, we'd get this.
Note a few things. First, it's not a circular region, nor is its centroid coincident with the neutral axis. Second, the banding artifacts are gone; those were all effects that occured as truncation begins at the gamut boundary. Lastly, the brightness of colors in this region looks uniform. It's almost difficult to tell that the center is gray. Compare the uniformity of the colors here to the diagram in the question.
Disregarding whether it's a good idea, if you wanted to normalize chroma, how would you do that? In order to normalize chroma, you'd need to know the chroma of the gamut boundary for any L,H pair. That's not a simple thing to calculate for LAB, because boundary chroma is not even a single-valued function of L and H. Making efforts to minimize the necessary error, boundary calculation and chroma normalization could be performed, but there are already tools to convert into chroma-normalized LAB that do that work internally.
sz = 300; % size of image
% set up base HuSLab image
[x y] = meshgrid(linspace(-110,110,sz));
[H S] = cart2pol(x,y);
H = rad2deg(H);
L = 50*ones(sz);
% mask off invalid pixels
L(S>100) = 0;
% this is part of MIMT (see File Exchange)
thisrgb = husl2rgb(cat(3,H,S,L),'lab');
% add a text label directly to the image
lbl = textim(sprintf('L = %d',round(50)),'ibm-iso-16x9');
thisrgb(10:size(lbl,1)+9,10:size(lbl,2)+9,:) = repmat(lbl,[1 1 3]);
% show all slices
imshow(thisrgb)
imwrite(thisrgb,'op1.png')
Note a few things. The radius here is not chroma. It's normalized chroma -- i.e. saturation. Second, because we've distorted the chroma space by normalizing it as a function of H, it's no longer apparently uniform.
So while normalizing chroma has its complications, it's possible. In the end, we get a diagram that doesn't represent LAB or LCHab, but a chroma-normalized variant (HuSLab/HSLab) instead. If you're finding this answer difficult to follow, then you should expect that your reader won't be able to blindly intuit what this diagram has to do with LAB.
As an aside, this example also allows us to implement the "largest inscribed circular region" option as well. Just change 'lab' to 'labp' in the call to husl2rgb(). We can expect it to be desaturated pastels. Note how close the neutral axis is to the gamut boundary in the previous diagram.
Do any of these details actually matter? That's a question that's left to you. If it's going to be printed in a book, it's not likely that utmost accuracy is warranted. The banding artifacts caused by truncation might not even show up. In fact, the inconsistent L in the original diagram may be considered beneficial, as the nonuniformity impoves the visual distinctness of hues as they progress around the circumference.
That said, if we're reduced to pretending that every color model is a finite cylindrical volume, then what's the purpose of suggesting that there are differences between the models? At what point do you tell the reader which particular subtle parts of your lesson were pure contrivance?

Image Analyst
Image Analyst am 9 Mai 2023

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 9 Mai 2023
Here are several fcn files on MATLAB file exchange to visualize cielab plot: https://www.mathworks.com/matlabcentral/fileexchange/40640-computational-colour-science-using-matlab-2e

Community Treasure Hunt

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

Start Hunting!

Translated by