[HELP] RGB histogram of an object

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
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
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 :(
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().

Iniciar sesión para comentar.

Image Analyst
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.
&nbsp
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.

Preguntada:

el 24 de Mayo de 2015

Respondida:

el 24 de Mayo de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by