MATLAB: How to plot a pizza bar with the colors found

bar plotcolor classificationdigital image processingimage processingImage Processing Toolboxpie chartsubplot

I want plot a pizza bar with my colors found, How can I do this?
This is my code:
%%*** [DADOS DO AUTOR] *** %%
%{
% Developed by: Marlon Vieira Damaceno
% email: marlonfaint@hotmail.com
% Faculdade de Tecnologia SENAI Porto Alegre 2017/2.
% Tecnólogo em Sistemas Embarcados.
% TCC - Análise Dermatológica Utilizando Técnicas de Processamento de Imagens.
% Analisa a imagem e atribui uma nota (0 - 6).
% Em funcao da presenca das cores: Marron claro, marron escuro, vermelho, azul, preto e branco.
% Rotina aplicada a analise de lesoes de pele - criterio da Regra ABCD.
% Marlon Vieira Damaceno e [Alexandre Haupt]
% Data: 14/11/2017.
% *** [COLOR FUNCTION] *** %
function [C] = COLORDETECT
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
rgbImage = imread('MELANOMA.jpg'); %ler a imagem
%%[EXTRACT THE INDIVIDUAL RED, GREEN, AND BLUE COLOR CHANNELS]
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
subplot(2,2,1);
imshow(rgbImage, 'DisplayRange',[]), colorbar;
title('Original RGB Image ', 'FontSize', fontSize);
subplot(2,2,2);
imshow(redChannel, 'DisplayRange',[]), colorbar;
title('Image Red', 'FontSize', fontSize);
subplot(2,2,3);
imshow(greenChannel, 'DisplayRange',[]), colorbar;
title('Image Green', 'FontSize', fontSize);
subplot(2,2,4);
imshow(blueChannel, 'DisplayRange',[]), colorbar;
title('Image Blue', 'FontSize', fontSize);
%%***CODE BAR PIZZA***%%
%%[FIND THE DARK BROWN PIXELS ON THE 3 CHANNELS]
darkbrownPixels = (redChannel > 109 & redChannel < 115) & (greenChannel > 78 & greenChannel < 82) & (blueChannel > 64 & blueChannel < 68);
%DARKBROWN = [ R=115 | G=82 | B=68 ] - faixa de erro definida pelo autor (5%)
numdarkbrown = sum(darkbrownPixels(:) == 1);
if (numdarkbrown > 0)
numdarkbrown = 1;
end
numdarkbrown
%%[FIND THE LIGHT BROWN PIXELS ON THE 3 CHANNELS]
lightbrownPixels = (redChannel > 188 & redChannel < 194) & (greenChannel > 142 & greenChannel < 150) & (blueChannel > 123 & blueChannel < 130);
%LIGHTBROWN = [ R=194 | G=150 | B=130 ] - faixa de erro definida pelo autor (5%)
numlightbrown = sum(lightbrownPixels(:) == 1);
if (numlightbrown > 0)
numlightbrown = 1;
end
numlightbrown
%%[FIND THE WHITE PIXELS ON THE 3 CHANNELS]
whitePixels = (redChannel > 243 & redChannel < 255) & (greenChannel > 243 & greenChannel < 255) & (blueChannel > 242 & blueChannel < 255);
%WHITE = [ R=243 | G=243 | B=242 ] - faixa de erro definida pelo autor (5%)
numwhite = sum(whitePixels(:) == 1);
if (numwhite > 0)
numwhite = 1;
end
numwhite
%%[FIND THE BLACK PIXELS ON THE 3 CHANNELS]
blackPixels = (redChannel > 0 & redChannel < 52) & (greenChannel > 0 & greenChannel < 52) & (blueChannel > 0 & blueChannel < 52);
%BLACK = [ R=52 | G=52 | B=52 ] - faixa de erro definida pelo autor (5%)
numblack = sum(blackPixels(:) == 1);
if (numblack > 0)
numblack = 1;
end
numblack
%%[FIND THE BLUE PIXELS ON THE 3 CHANNELS]
bluePixels = (redChannel > 0 & redChannel < 56) & (greenChannel > 0 & greenChannel < 61) & (blueChannel > 150 & blueChannel < 255);
%BLUE = [ R=56 | G=61 | B=150 ] - faixa de erro definida pelo autor (5%)
numblue = sum(bluePixels(:) == 1);
if (numblue > 0)
numblue = 1;
end
numblue
%%[FIND THE RED PIXELS ON THE 3 CHANNELS]
redPixels = (redChannel > 175 & redChannel < 255) & (greenChannel > 0 & greenChannel < 54) & (blueChannel > 0 & blueChannel < 60);
%RED = [ R=175 | G=54 | B=60 ] - faixa de erro definida pelo autor (5%)
numred = sum(redPixels(:) == 1);
if (numred > 0)
numred = 1;
end
numred
%%[SUM OF ALL COLORS DETECTED]
numcolor = numlightbrown + numdarkbrown + numwhite + numblack + numblue + numred;
numcolor
c = categorical({'DarkBrown','LightBrown','White','Black','Red','Blue'});
values = [numdarkbrown numlightbrown numwhite numblack numred numblue];
%bar(c, values)
end

Best Answer

Use the pie() function.
By the way, that doesn't look like a very robust algorithm and has several problems. For example no color calibration, classification in RGB color space, etc. Have you looked at the gamut of your image with colorcloud()? Why do you think segmentation/classification in RGB color space would work? Do you think you can carve out a rectangular block in RGB space to get each of those colors accurately? I doubt it. Skin cannot be segmented by thresholding in any color space for all colors of skin because the gamut of skin is shaped like a banana. But that's a whole other discussion. Start with pie() and then you'll run into other problems soon and then can work on tackling those.