I need to compute a background model using the information below can someone please help me in understanding and implementing the idea below

To compute this background model all of the pixels in the image are histogrammed-namely, for each pixel its color intensity is placed in the proper bin of a preferred possible 256 intensity levels. This is preferably done for each of the red, green and blue (RGB) channels thus generating three separate histograms. Alternately, one histogram could be generated using some joint space rep- resentation of the channels. Once the histogram has been computed, a Gaussian distribution for each histogram is calculated to provide the mean pixel intensity of the background and the vari- ance.

Answers (1)

Depends on what your background image is. I use polyfitn ( http://www.mathworks.com/matlabcentral/fileexchange/34765-polyfitn) to get a smooth illumination profile that I can use to correct for non-uniform lighting. But if you had, say a street scene with a bunch of people on it, then you wouldn't use that method, you'd take the mode or use GMM models or something.
I don't see how your proposed method would work at all. I don't even know what it does, except maybe get the mean color of the image, but you don't need to fit histograms to Gaussians to do that, or even to take histograms at all. Basically your method is just the same as:
meanRedValue = mean(rgbImage(:,:,1));
meanGreenValue = mean(rgbImage(:,:,2));
meanBlueValue = mean(rgbImage(:,:,3));
That's all your algorithm does, which is not even as locally adaptive as a blurring with conv2(). That's not really background correction at all.

7 Comments

what does this statement mean " for each pixel its color intensity is placed in the proper bin of a preferred possible 256 intensity levels."? I just want to implement the background model in this way could you please help me doing that, doesn't matter what type of image is please help me in following the given sequence.Thanks
Let's say you have a uint8 image with 256 gray levels. Now let's say you're scanning across all the pixels in the image and your current pixel has an RGB value of (100, 120, 140). You'd have 3 histogram arrays, each 256 elements (bins) long. In the red histogram array, you'd increment the element at 100 by 1 for that one pixel you're examining. Similarly you'd increment the green histogram array at 120 and you'd increment the bin for gray level 140 for the blue array.
like this?
rgbImage=imread(images);
[rows columns numberOfColorBands] = size(rgbImage);
%I am using loop to to initialize with 0 in spite of using zeros function because the index starts with 1 by default
for i=1:256
rhistogram(i)=0;
ghistogram(i)=0;
bhistogram(i)=0;
end
for i=1:rows
for j=1:columns
% this can also be done using rgbvalues=impixel(rgbImage,j,i);
%r=pixel(1);g=pixel(2);b=pixel(3);
r=rgbImage(i,j,1);
g=rgbImage(i,j,2);
b=rgbImage(i,j,3);
if r==0
r=256;
rhistogram(r)=rhistogram(r)+1;
else
rhistogram(r)=rhistogram(r)+1;
end
if g==0
g=256;
ghistogram(g)=ghistogram(g)+1;
else
ghistogram(g)=ghistogram(g)+1;
end
if b==0
b=256;
bhistogram(b)=bhistogram(g)+1;
else
bhistogram(b)=bhistogram(g)+1;
end
end
end
lastCol=rhistogram(columns);
rhistogram=rhistogram(1:columns-1);
rhistogram=[lastCol rhistogram];
lastCol=ghistogram(columns);
ghistogram=ghistogram(1:columns-1);
ghistogram=[lastCol ghistogram];
lastCol=bhistogram(columns);
bhistogram=bhistogram(1:columns-1);
bhistogram=[lastCol bhistogram];
imhist(rhistogram);
imhist(ghistogram);
imhist(bhistogram); If I have to do for multiple images how do I have do I mean would I be continuing incrementing values in same arrays or concatenate the previous values into other variable.And what is the next step after this?
No, you don't want to do that. You don't want to write your own nested for loop manual procedure for getting a histogram when you can just call imhist(). Anyway, why do you want the histogram anyway when you can just use the three lines I gave you to determine the mean, which is what you asked about? A similar 3 lines using std() and var() will get you the standard deviation and variance.
Can you give me a complete code for this since I am completely blank now.I need to do this for couple of images not for a single image. I have lets say 10 images and I have to compute background model this way using all 10 images.

Sign in to comment.

Asked:

on 2 Aug 2012

Community Treasure Hunt

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

Start Hunting!