MATLAB: How to draw a colour bar with known discrete RGB values and known percentage of pixels represent each RGB values

clustering analysiscolour bardominant colorimage processing

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.

Best Answer

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')