Average histogram of R,G,B histograms

1 次查看(过去 30 天)
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

采纳的回答

Ridwan Alam
Ridwan Alam 2019-12-17
编辑:Ridwan Alam 2019-12-17
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)
  10 个评论
Ridwan Alam
Ridwan Alam 2019-12-19
编辑:Ridwan Alam 2019-12-19
Oh. So sorry just saw these comments, specially the original question.
X = im2double(imread('peppers.PNG'));
R = X(:,:,1);
G = X(:,:,2);
B = X(:,:,3);
peppers.png
(a) Histogram-equalize the R, G, and B images separately using the histogram-equalization program and convert the image back to tif format.
Req = histeq(R,256); figure; imshow(Req);
Geq = histeq(G,256); figure; imshow(Geq);
Beq = histeq(B,256); figure; imshow(Beq);
Xeq = cat(3,Req,Geq,Beq);
figure;imshow(Xeq);
% it looks different than X because of the separate hist equalization of R,G,B
peppers1.png
(b) Form an average histogram from the three histograms in(a) and use it as the basis to obtain a single histogram equalization intensity transformation function. Apply this functionto the R, G, and B components individually, and convert the results to jpg. Compare and explain the differences in the tif images in (a) and (b).
[countsR,edgesR]=histcounts(R,linspace(0,1,256));
[countsG,edgesG]=histcounts(G,linspace(0,1,256));
[countsB,edgesB]=histcounts(B,linspace(0,1,256));
figure, plot(edgesR(1:end-1),countsR,'r')
figure, plot(edgesG(1:end-1),countsG,'g')
figure, plot(edgesB(1:end-1),countsB,'b')
mean_counts = mean([countsR(:), countsG(:), countsB(:)], 2);
figure, plot(edgesR(1:end-1),mean_counts)
Reqm = histeq(R,mean_counts);
figure;imshow(Reqm)
Geqm = histeq(G,mean_counts);
figure;imshow(Geqm)
Beqm = histeq(B,mean_counts);
figure;imshow(Beqm)
% convert
Xeqm = cat(3,Reqm,Geqm,Beqm);
figure;imshow(Xeqm)
peppers2.png
Image Analyst
Image Analyst 2019-12-19
No, I don't think so. Again, your code will just do histogram matching, like I and the help said. You can't pass in some histogram with some non-flat shape if you want a flat output histogram. You can do that for a single gray scale image, but for the color image task it asked, you have to take the mean_counts, then compute the CDF with cumsum() then invert it and use intlut() to transform each color channel and then use cat() to recombine them. You can't do what it asked with the built-in histeq() function.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2019-12-17
I wouldn't do it like that. You'd probably have the least annoying result if you transformed to HSV color space with rgb2hsv(), then called histeq() on the V channel ONLY, then get back to RGB space with hsv2rgb(). That said, usually histogram equalization looks crummy - it's just a mathematical curiosity that beginners like to try but no one really uses to make pleasing pictures. Once you try it you'll see what I mean. Bad pictures. Would be better to just use a gamma or linear stretch rather than the unnatural stretch of histogram equalization which gives harsh, lousy looking images.
  2 个评论
Maryam Al-Muhaini
Maryam Al-Muhaini 2019-12-17
unfortunatlly, I'm doing a homework and I've been asked to do this :(
Image Analyst
Image Analyst 2019-12-17
Then you can still call rgb2gray() then get the histogram, then the CDF by using cumsum(), and then the transform. Then apply it to each color channel.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by