[HELP] RGB histogram of an object
Afficher commentaires plus anciens
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!! =)
Réponses (2)
Image Analyst
le 24 Mai 2015
0 votes
Don't use surf(). Use imhist() to get the counts, and plot() or bar() or area() to plot the histogram. See attached demo.

2 commentaires
Image Analyst
le 24 Mai 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
le 24 Mai 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
le 24 Mai 2015
0 votes
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.

Catégories
En savoir plus sur Histograms dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!