[HELP] RGB histogram of an object
Mostrar comentarios más antiguos
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!! =)
Respuestas (2)
Image Analyst
el 24 de Mayo de 2015
0 votos
Don't use surf(). Use imhist() to get the counts, and plot() or bar() or area() to plot the histogram. See attached demo.

2 comentarios
Image Analyst
el 24 de Mayo de 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
el 24 de Mayo de 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
el 24 de Mayo de 2015
0 votos
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.

Categorías
Más información sobre Histograms en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!