Help with effective data structure, to represent CIE Lab ab diagram
4 次查看(过去 30 天)
显示 更早的评论
I'm at a point where I'm making progress on my project even though I'm surely not approaching it from an efficient coding perspective, not taking advantage of the modeling efficiency that linear algebra offers? But, here goes. As can be seen from my code and the screen capture, I'm trying to create a CIE Lab 'ab' diagram. This is my humble code :
clc
global ax;
fig=figure('Position', [600 300 1000 1000]);
ax = axes(fig);
axis([-128 128 -128 128]);
xticks([-128 -112 -96 -80 -64 -48 -32 -16 0 16 32 48 64 80 96 112 128]);
yticks([-128 -112 -96 -80 -64 -48 -32 -16 0 16 32 48 64 80 96 112 128]);
grid on;
grid minor;
hold on;
OffsetX=-96;
OffsetY=0;
Axe_A = transpose(linspace(-96, 96, 49));
Axe_L = transpose(linspace(50, 50, 49));
Axe_B = transpose(linspace(0, 0, 49));
InGamut = transpose(linspace(0, 0, 49));
Lab = [Axe_L, Axe_A, Axe_B];
RGB = lab2rgb(Lab);
%Add 4th column to flag out of gamut colors
RGBx = [RGB InGamut];
[row,col] = size(RGB);
for ROW = 1:row
if RGB(ROW,1) < 0
RGBx(ROW,1) = 0;
RGBx(ROW,4) = 1;
end
if RGB(ROW,1) > 1
RGBx(ROW,1) = 1;
RGBx(ROW,4) = 1;
end
if RGB(ROW,2) < 0
RGBx(ROW,2) = 0;
RGBx(ROW,4) = 1;
end
if RGB(ROW,2) > 1
RGBx(ROW,2) = 1;
RGBx(ROW,4) = 1;
end
if RGB(ROW,3) < 0
RGBx(ROW,3) = 0;
RGBx(ROW,4) = 1;
end
if RGB(ROW,3) > 1
RGBx(ROW,3) = 1;
RGBx(ROW,4) = 1;
end
end
T = RGBx;
OffsetX=-96;
OffsetY=0;
for ROW = 1:row
if RGBx(ROW,4) == 0
rectangle(ax,'Position',[OffsetX OffsetY 4 4],'FaceColor',[RGBx(ROW,1) RGBx(ROW,2) RGBx(ROW,3)], 'LineStyle', 'none');
else
rectangle(ax,'Position',[OffsetX OffsetY 4 4],'FaceColor',[RGBx(ROW,1) RGBx(ROW,2) RGBx(ROW,3)]');
end
OffsetX=OffsetX+4;
end
hold on;
FirstLine = [-128, -112, -96, -80, -64, -48, -32, -16, 0, 16, 32, 48, 64, 80, 96, 112, 128];
array = zeros(17, 17);
for k = 1:17
array(k,:) = FirstLine;
end
for m= 1:17
for k = 1:17
scatter(array(1,m), array(1,k));
end
end
alpha(.5)
And this is the result :
As far as plotting the Lab values, at the constant L* = 50 value, I use a 'tile' size of 4x4. (Later, when I'm satisfied, I'll expand this to 1x1 or 2x2). As you can see from the screen capture, I only have one row worth of data.
The stumbling block I'm hitting is I don't know how best to represent the entire Lab values, from -128 to 128, in a* and b* under, possibly, one data structure?
I sense that, I could possibly expand the following line :
Lab = [Axe_L, Axe_A, Axe_B];
... into a Lab(49) array, which would be a monster array of 49 'outer rows' each containing 49 columns of a* and b* sub-arrays? And that's where I'm kind of stuck because I'm not sure this makes any kind of programming sense. I've been thinking about how best to approach this for a while now and I'm probably at the stage of asking for suggestions...
BTW, I intend to reduce the opacity of the 'circles' close to 0 so that they're not materially changing the underlying rectangle colors while giving me the benefit of data tips.
Before taking my whole current approach, I toyed with the idea of using a colormap, to hold the Lab2rgb values but I'm not sure that was the best approach.
Thank you in advance for your kind help and patience.
I noticed I'm using loops that considerably slow down the script execution but I'm not really concerned about speed.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Detection 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!