MATLAB: Average histogram of R,G,B histograms

histogramimage processing

I need to find the avrege of histograms B,R,G that I already found using this code so can you please help me?
after finding the average I need to use it as the basis to obtain a single histogram equalization intensity transformation function so how is that specifically done?
this the code I used
X = im2double(imread('Capture.PNG'));
R = X(:,:,1);
G = X(:,:,2);
B = X(:,:,3);
z = zeros(size(R));
Rimg = cat(3, R, z, z);
Gimg = cat(3, z, G, z);
Bimg = cat(3, z, z, B);
L256 = linspace(0,1,256).';
z256 = zeros(256,1);
mapR = [L256, z256, z256];
mapG = [z256, L256, z256];
mapB = [z256, z256, L256];
figure; image(Rimg); colormap(mapR); colorbar();
figure; image(Gimg); colormap(mapG); colorbar();
figure; image(Bimg); colormap(mapB); colorbar();
I=imread('Capture.PNG');
counts1=imhist(I(:,:,1));
counts2=imhist(I(:,:,2));
counts3=imhist(I(:,:,3));
figure, plot(counts1,'r')
figure, plot(counts2,'g')
figure, plot(counts3,'b')
mean_counts = mean([counts1(:), counts2(:), counts3(:)], 2);
figure, plot(mean_counts)
help me please

Best Answer

I=imread('Capture.PNG');
[counts1,edges1]=histcounts(I(:,:,1),linspace(0,1,256));
[counts2,edges2]=histcounts(I(:,:,2),linspace(0,1,256));
[counts3,edges3]=histcounts(I(:,:,3),linspace(0,1,256));
figure, plot(edges1(1:end-1),counts1,'r')
figure, plot(edges2(1:end-1),counts2,'g')
figure, plot(edges3(1:end-1),counts3,'b')
mean_counts = mean([counts1(:), counts2(:), counts3(:)], 2);
figure, plot(edges1(1:end-1),mean_counts)
J = histeq(I,mean_counts)