Creating a circle with segments of colour
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to create an image of a circle, with segments of colour. The way I think to do it to either create two circles, one smaller than the other, and fill the gap in between with colour (seems unnecessary, since if I create a circle of colour anyway). Easier might be to create a circle made up of different colours, and fill the rest in with black.
It seems to be easiest using RGB colours, and creating segments each with a specific colour in them, then just specify the colour and width of the segments to create coarser/finer rainbow structure, for example.
Any ideas to create a circle made up of segments, which are adjustable both in number, and colour, in an easy way?
0 commentaires
Réponse acceptée
David Young
le 30 Sep 2014
Modifié(e) : Image Analyst
le 1 Oct 2014
Not sure what you mean by "adjustable in colour". The code below does the full colour wheel - it should give you a starting point anyway.
% Set parameters (these could be arguments to a function)
rInner = 80; % inner radius of the colour ring
rOuter = 200; % outer radius of the colour ring
ncols = 12; % number of colour segments
% Get polar coordinates of each point in the domain
[x, y] = meshgrid(-rOuter:rOuter);
[theta, rho] = cart2pol(x, y);
% Set up colour wheel in hsv space
hue = (theta + pi) / (2 * pi); % hue into range (0, 1]
hue = ceil(hue * ncols) / ncols; % quantise hue
saturation = ones(size(hue)); % full saturation
brightness = double(rho >= rInner & rho <= rOuter); % black outside ring
% Convert to rgb space for display
rgb = hsv2rgb(cat(3, hue, saturation, brightness));
% Check result
imshow(rgb);
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!