[HELP] RGB histogram of an object
3 views (last 30 days)
Show older comments
Hey guys!! I'm new on MATLAB and I was trying to build the RGB histogram of the object that appears in an image. To do that I have the image of the background and the image of the same background with the object in the foreground.
I tried this code but it doesn't work :( Any ideas?
A = imread('background.jpg');
B = imread('image.jpg');
d = double(B)- double(A);
R = d(:, :, 1);
G = d(:, :, 2);
B = d(:, :, 3);
Color = d/255;
surf(R,G,B,Color);
Thank youuu!! =)
0 Comments
Answers (2)
Image Analyst
on 24 May 2015
Don't use surf(). Use imhist() to get the counts, and plot() or bar() or area() to plot the histogram. See attached demo.
2 Comments
Image Analyst
on 24 May 2015
amelia's "Answer" moved here because it's really a comment to me and not an answer to her original question:
I'm using surf because I want the 3D histogram, not 3 histograms 2D like you did :(
Image Analyst
on 24 May 2015
Then you need to do
hist3D(R+1, G+1, B+1) =
hist3D(R+1, G+1, B+1) + 1
In other words, you need to build up the true 256 by 256 by 256 3D histogram. surf() does not build histograms, neither does hist2d().
Image Analyst
on 24 May 2015
I do have this attached demo that calculates the 3D histogram. See attached file below the image it creates.
 
If you want a better one that includes a lot more powerful visualizations, see Color Inspector 3D. It's an imageJ plugin but you can use it from MATLAB.
0 Comments
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!