Skip to content

Instantly share code, notes, and snippets.

@jnkather
Created July 22, 2015 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnkather/77ab1f64357bc5440766 to your computer and use it in GitHub Desktop.
Save jnkather/77ab1f64357bc5440766 to your computer and use it in GitHub Desktop.
Show the RGB gamut in RGB space and CIELAB space, then rotate the cubes and save the frames as image files
% JN Kather, 2015
% Show the RGB gamut in RGB space and CIELAB space, then
% rotate the cubes and save the frames as image files to
% a subfolder ./output
% set parameters
turns = 1; % how often should the viewpoint turn, default 1
balls = 70; % how many balls to plot
nSteps = 40; % how many viewpoints?, default 40
saveOutput = false; % save output to files? default false
imgResolution = '-r150';
saveDir = 'output/';
% set constants
rgb = true; % plot RGB cube, default true
lab = true; % plot CIELAB cube, default true
% initialize color cube
[X,Y,Z] = (meshgrid((linspace(0,1,balls))));
colors = ([X(:),Y(:),Z(:)]);
%clear the interior of the cube
var1 = (max(colors')'<1);
var2 = (min(colors')'>0);
colors = colors(:);
mask = repmat((var1 + var2) == 2,3,1);
colors(mask) = [];
% reformat to column vectors
colors = reshape(colors,[],3);
% main part
if rgb % part 1: RGB
% plot in RGB space
colorsRGB = colors;
figure();
scatter3(colorsRGB(:,1),colorsRGB(:,2),colorsRGB(:,3),250,colors,'filled');
axis equal
set(gcf,'Color','w');
view(1,30)
axis off
% rotate
for i=linspace(1,(360*turns),nSteps)
view(i,30);
drawnow;
if saveOutput
print(gcf,[saveDir, 'RGB-',num2str(1000+i),'.png'],'-dpng',imgResolution)
end
pause(0.01)
end
end
if lab % part 2: CIELAB
% plot in CIELAB space
figure();
colorsLAB = rgb2lab(colors);
scatter3(colorsLAB(:,1),colorsLAB(:,2),colorsLAB(:,3),250,colors,'filled');
set(gcf,'Color','w');
view(1,30)
axis([0 100 -100 100 -100 100]);
axis off;
% rotate
for i=linspace(1,(360*turns),nSteps)
view(i,30)
drawnow;
if saveOutput
print(gcf,[saveDir, 'LAB-',num2str(1000+i),'.png'],'-dpng',imgResolution)
end
pause(0.01)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment