I'd like to plot color image histograms that combine color as RGB

21 views (last 30 days)
I'd like to plot a histogram of color images that look like this
when each color band overlaps it change colors according to the RGB combination of it. Like Red-Green overlapped area produces Yellow, Green-Blue produces Cyan etc.
Thank you in advance.

Answers (1)

Adam Danz
Adam Danz on 5 Aug 2020
Edited: Adam Danz on 5 Aug 2020
By setting transparency to a value less than 1, overlapping histograms will show the combined colors. However, since the histogram colors are transparent, they aren't truely red, blue, and green and therefore the color combinations won't be truely yellow and cyan.
gaus = @(x,mu,sig,amp,vo)amp*exp(-(((x-mu).^2)/(2*sig.^2)));
x = 1:100;
g1 = gaus(x,10,5,10);
g2 = gaus(x,28,5,12);
g3 = gaus(x,43,11,7);
figure()
hold on
bins = 0:100;
h(1) = histogram('BinEdges',bins,'BinCounts',g1, 'FaceColor', 'b');
h(2) = histogram('BinEdges',bins,'BinCounts',g2, 'FaceColor', 'g');
h(3) = histogram('BinEdges',bins,'BinCounts',g3, 'FaceColor', 'r');
The transparency levels can be changed using
set(h,'FaceAlpha',.4) % 0=completely transparent, 1=opaque
Of course you could compute the individual bar positions (histcounts) and which ones overlap in order to plot the overlapping and non-overlapping regions individually. Then you could set the colors of overlapping and non-overlapping regions independently.
  2 Comments
Adam Danz
Adam Danz on 6 Aug 2020
Edited: Adam Danz on 10 Aug 2020
Yes, my first paragraph tells you why it isn't exactly what you wanted.
My last paragraph tells you how to get exactly what you want but it will take some work.
The answer shows the best alternative.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!