How can i plot the YCbCr histograms with the correct colour points (0-255)
Afficher commentaires plus anciens
Hi,
So i am trying to replicate one of MATLAB's plots but unsure how to get the varying change in colour in the histograms that depend on the pixel value (0-255). YCbCr file is what im trying to achieve. This is what i have so far.
img = imread('peppers.png');
ycbcr=rgb2ycbcr(img);
Y = ycbcr(:,:,1);
Cb = ycbcr(:,:,2);
Cr = ycbcr(:,:,3);
figure;
subplot(311);
histogram(Y,'BinMethod','integers','EdgeAlpha',0,'FaceAlpha',1);
title('Y');xlim([0 255]);
subplot(312);
histogram(Cb,'BinMethod','integers','EdgeAlpha',0,'FaceAlpha',0.7);
title('Cb');xlim([0 255]);
subplot(313);
histogram(Cr,'BinMethod','integers','EdgeAlpha',0,'FaceAlpha',0.7);
title('Cr');xlim([0 255]);
Réponse acceptée
Plus de réponses (1)
You would want to change the CData property of the histograms, which would let you set the colour of each individual bar. However, I don't think histograms actually have this property - only bar charts:
You probably need to get the histogram counts, and then manually plot a graph of them. Someone called Wolfie on StackExchange created this example. I'll copy it here for reference (changing the data variable x to a random array, just so it is runnable), but they deserve the credit!
[h,edges] = histcounts(rand([1 100]),10); % calculate the histogram data
b = bar( (edges(1:end-1)+edges(2:end))/2, h ); % plot the bar chart
b.BarWidth = 1; % make the bars full width to look the same as 'histogram'
b.CData = parula( 10 ); % generate colours as a 10x3 array (columns are RGB), can
% do this manually if you want
b.FaceColor = 'flat'; % Make 'bar' use the CData colours
Catégories
En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!











