view graphics/colour/hsvx.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents 82075c94eed1
children
line wrap: on
line source
% hsvx - HSV colour map with extended functionality
%
% hsvx :: N:natural -> [[N,3]] ~'same as hsv'.
%
% hsvx :: 
%    N:natural ~'size of colormap to return', 
%    0--1 ~'inital hue', 
%    0--1 ~'saturation', 
%    0--1 ~'value' 
%    options {
%       brightness :: real/0 ~'try to get even perceptual brightness: 0 not, 1 full'
%    }
% -> [[N,3]].

function M=hsvx(N,H0,S,V,varargin)

	if nargin<2, H0=0; end
	if nargin<3, S=1; end
	if nargin<4, V=1; end
	opts=options('brightness',0,varargin{:});

	H=linspace(H0,H0+1,N+1);
	M=hsv2rgb([mod(H(1:end-1),1)',repmat([S,V],N,1)]);
	if opts.brightness >0
		L=luminocity(M).^opts.brightness;
		M=M./repmat(L,1,3);
		M=V*M./max(max(M));
	end
end