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

9 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.
  4 Comments
Tong Minh Hoa
Tong Minh Hoa on 24 May 2024
How to set the colors of overlapping and non-overlapping regions independently?
Can you help me?
DGM
DGM on 24 May 2024
Edited: DGM on 24 May 2024
Here's an example.
% a test image
inpict = imread('rgbdistRGBCMY.png');
% a parameter
nbins = 256;
% get bin counts and positions
counts = zeros(nbins,7);
[counts(:,1) centers] = imhist(inpict(:,:,1),nbins); % R
counts(:,2) = imhist(inpict(:,:,2),nbins); % G
counts(:,3) = imhist(inpict(:,:,3),nbins); % B
counts(:,4) = min(counts(:,[2 3]),[],2); % C
counts(:,5) = min(counts(:,[1 3]),[],2); % M
counts(:,6) = min(counts(:,[1 2]),[],2); % Y
counts(:,7) = min(counts(:,1:3),[],2); % W
% plot everything
hb = gobjects(7,1);
chancolors = {'r','g','b','c','m','y','w'};
hold on;
for k = 1:7
hb(k) = bar(centers,counts(:,k),1,chancolors{k});
end
ylim([0 3000])
Personally, I think it only makes the histogram hard to read and can easily become misleading.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!