How do I draw a colour bar with known discrete RGB values and known percentage of pixels represent each RGB values?
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I extracted 3 key colours from an image using clustering method. The RGB values of the 3 colours are as below:
RGB1=[24 70 187]; (blue)
RGB2=[208 118 22]; (orange)
RGB3=[88 90 28]; (olive green)
My question is:
How to draw a colour bar (shown below) in matlab with the 3 known colours and the known percentage of the pixels represent each colour (blue 50%, orange 30%, and olive green 20%). In this fashion it tells that the dominant colour extracted from the image is blue followed by orange, then olive green.
Currently this colour bar was drawn in photoshop unfortunately.
0 个评论
采纳的回答
Jan
2018-1-24
编辑:Jan
2018-1-24
As pixel image:
Map = [24 70 187; 208 118 22; 88 90 28] / 255;
Ind = repmat(repelem([1, 2, 3], [50, 30, 20]), 40, 1);
RGB = ind2rgb(Ind, Map);
figure;
image(RGB)
Or as patch:
Map = [24 70 187; 208 118 22; 88 90 28] / 255;
a = 0.5; b = 0.8;
vert = [0 0; 0 1; a 1; a 0; b 1; b 0; 1, 1; 1, 0];
face = [1, 2, 3, 4; 4, 3, 5, 6; 6, 5, 7, 8];
figure;
patch('Vertices', vert, 'Faces', face, ...
'FaceVertexCData', Map, ...
'FaceColor', 'flat', 'EdgeColor', 'none')
更多回答(1 个)
Benjamin Kraus
2018-1-24
values = [0.5 0.3 0.2];
colors = [24 70 187; 208 118 22; 88 90 28]/255;
n = numel(values);
x = [0 cumsum(values)].*[1;1];
y = ones(2,n+1).*[1;0];
vertices = [x(:) y(:)];
faces = [1 2 4 3]+((2:2:2*n)-2)';
p = patch(...
'Vertices',vertices,...
'Faces',faces,...
'FaceVertexCData', colors, ...
'FaceColor', 'flat');
xlim([-0.1 1.1]);
ylim([-0.1 1.1]);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!