This demo try to identify the location of red object in a movie.
Could you explain for me some questions following.
- How to determine likelihood function
-Xstd_rgb = 50;Xstd_pos = 25;Xstd_vec = 5;
Thanks a lot
You can also download my C++ version using OpenCV. Hope you enjoy.
I am working on "Parameterizable FPGA framework for particle filter based object tracking in video". Are your algorithm and algorithm mentioned in this paper same? I would like to know whether bhattacharya co-efficient is used or not?
I need histogram si I(x,y)<=vallé1 alors R(x,y)=1
sinon si I(x,y)>vallé1 et I(x,y)<vallé2 alors R(x,y)=2
Thank your for a comment. As for your question, I do not have clear answer.
I used this model just because this is the only one I could think of at that moment. I didn't know the model you show below...
Your model might be good one, but I don't have any information I could share. Sorry!
Hello Eiji. Really good job writing the code. I think I finally understand particle filters after watching many youtube videos and reading many papers and tutorials. I think your code was the most helpful part !!! Thank you!
I have a question about update_particle.m. Specifically you have new velocity defined as
X(3:4,:) = X(3:4,:) + Xstd_vec * randn(2, N);
I understand that using this algorithm, the velocity of the spots that are red a favored and settle on the correct number. I have also seen in other papers people defining velocity as
X(3:,4) = gamma*( X(1:2,:)(t) - X(1:2),:)(t-1)) + Xstd_vec * randn(2, N) * (1-gamma) ;
Basically this way you define velocity as actual velocity of the spot( difference in coordinates at two time points) + the random factor. Gamma is just a parameter that specifies how much of velocity should be random and how much specified by the measured velocity.
I was wondering why you chose your option instead of this one and if you think one option is better than the other one in some concepts. Any thoughts and comments would be greatly appreciated!!!
I'm trying to write a code that tracks multiple people that can cross each other and they do not have a specific color attached to them.
Thank you for comments.
For your purpose, modifying this code might not be a good idea... Computer Vision System Toolbox provides a good function called vision.ForegroundDetector.
This function detect anything that moves.
hello Eiji, thanks for this wonderful code.
How this code can be modified to track any moving object/objects where no other properties like color, shape etc. are considered?
OK,it is simple but rearlly interesting!Thank you!
For this type of problems, tech support has a lot of information. So, asking mathworks' tech support would be best.
If you want to check it yourself, I think checking if you can play WMV-file on you PC would be a first step I guess.
If you try to track two color, I think you can think of the distribution which has two peaks in RGB color space.
It's going to be the distribution two gaussian distribution combined. It is called mixture gaussian distribution.
If you have distribution, you can calculate likelihood.
As for your question, please let me recommend you a function called "rgb2hsv" you might know.
But I'm thinking that if you convert color RGB color space to HSV color, the distribution of noise might change too.
So, you have to change the way to calculate log-likelihood too.
I'm supposing gaussian noise in RGB-color space. But I'm not sure this supposition is fair or not. I do not have any substantial reason for this supposition.
Please remember that this is a toy demo.
If you have camera you use, I think you can check the pattern or distribution of noise you get when you observe some color using your camera.
For example, if you prepare big red sheet and monitor it under various environments, you can guess how color changes according to lighting condition or some other factor.
Then you can guess the distribution of noise you get when you track something by color, I think.
read giving error .Prompts to stop matlab .Maybe problem with the video.I have matlb 2013a
Hi Mr Eiji
first of all thanks for the the code and it works really well.
Could you help me, i am trying to track two color channels (blue and red)at the same time.
I changed the
Xrgb_trgt = [ 255; 0; 0 ]; to Xrgb_trgt = [ 0; 0; 255];
and it tracks the blue channel too but could you assist with how i can track both red and blue channels ? Thanks and also when i run it the particles seemed to be only appearing in one corner please help thankyou
Thank you for the code. I want to use HSV color space for particle filtering. can you please suggest the way to calculate log-likelihood usig HSV color components?
A and B are used for the calculation of log likelihood. This log likelihood is calculated under the assumption that RGB color of the object is observed with gaussian noise. But this assumption might not be true. Please think this is a toy to understand particle filter.
thank you for sharing code.My question is why do you use the formula：
A = -log(sqrt(2 * pi) * Xstd_rgb);
B = - 0.5 / (Xstd_rgb.^2);
to make the likelihood,which reasons was it based on?
what is a reference implementation (eg, paper).
Compared with particle filter, Kalman filter is relatively light algorithm.
If the object moves really really fast, fining object frame by frame might be an idea...
How to modify this code to detect and track objects which are very fast moving in a video?
First of all, thanks for sharing the code, it helps me a lot. I will ask question about parameters :
Xstd_rgb = 50;
Xstd_pos = 25;
Xstd_vec = 5;
How did you find the numbers like 50,25 and 5?
I want to generalize this for every color not spesific to red one. So, how can I start to modify this program ?
Would let me know the version of MATLAB you use? I've heard 64bit version of old MATLAB cannot handle video properly.
How can I open a video in this program. GUI is running ok but no video being shown.
Eiji Ota Can you help please.
Thanks Mr.Eiji Ota you are kindly many thanks.
Sorry for poorly commented code...
"Xstd_rgb" means standard deviation of observation noise, which means noise you get when you observe the state of something.
"Xstd_pos" and "Xstd_vec" mean standard deviation of system noise, which describes how far actual movement of target object differs from the ideal model (in this case, linear uniform motion).
State space become of 2 componets, one is "position of particle" and another is "speed of particle".
You can define these 3 types of noise by these parameters.
Plz Mr.Eiji Ota can you explain these parameters use for what ?
Xstd_rgb = 50;
Xstd_pos = 25;
Xstd_vec = 5;
I made this program based on several books written in Japanese. There's no paper related to this demo. Sorry...
You can find several papers or tutorial documents if you search internet by these keywords, "particle filter", "color tracking", "condensation".
Please, can I know from which paper does this project described, thanks !
Thanks Mr.Eiji Ota
Computer Vision System Toolbox now supports Kalman filter.
If you want to track object using Kalman filter, Computer Vision System Toolbox could be an answer.
But, if you want to know how Kalman filter works, I do not have any good example for Kalman filter. Sorry...
Mr. Ota do you have code for tracking object color using kalman filter?
Initial location of each particle is decided by random numbers. And initial speed is set to zero. Initial conditions are decided by function "create_particles".
sir can u explain what is the initial state here you are taking.......and how the code is working
Recently I heard this demo program doesn't work with 64bit version of MATLAB in some cases.
Sorry for inconvinience... Please use 32bit version when you run this demo.
This type of problem might happen if you are using Mac OS (The movie file I attached was windows media video).
Or video decoding function of windows OS might have some problem.
Asking support center might be the fastest way to solve this type of problem because they have a lot of information about OS related problems.
hello, thanks for your contribution.
I got a problem with ''particle_filter_by_saved_movie.m file'' the error shows like [Dot name reference on non-scalar structure. Error in VideoReader/read (line 91) if( ~isempty(obj.NumberOfFrames) )] I don't know why? can you help me ? thank you
"calc_log_likelihood.m" is the function which calculates log likelihood according to normal distribution.
In this function, you can find an if statement like this...
if I && J
C = double(Y(:, m, n));
D = C - Xrgb_trgt;
D2 = D' * D;
L(k) = A + B * D2;
L(k) = -Inf;
This is the part where this program calcuate the loglikelihood. I set "-Inf" for the particles which go outside of picture.
Enjoy tweaking, Atef!
Mr.Ota please can I change the code to apply another distribution function.
thanks Mr.Ota for this code.
Thank you, pooja. Enjoy tweaking!
Oh this is interesting. I wonder if I can tweak the code to apply information filter instead of particle filter.
Thanks for this Mr.Ota
Thanks Mr.Eiji Ota
I made this program based on several books written in Japanese. There's no paper I can recommend. Sorry...
You can check the basic concept of particle filter by wikipedia.
can you send me the paper for this work
I'd like to applay this code using beta filter " beta distribution maximum likelihood "
I think rgb2hsv can be used for the conversion of color space. In this demo,
I think this function is used for the conversion of color space from RGB to HSV.
If you change the function "calc_log_likelihood.m", you can change how you calculate likelihood.
Please, I will use this code to track the face of person how do I change the resampling function given that I used the intesection of HSV histogram as a function likelhood. Please help me. it is critical to know this. thanks a lot.
I've never tried to track other color, but you can try quite easily.
Open the main file "particle_filter_by_saved_movie.m", and edit following part.
Xrgb_trgt = [255; 0; 0];
This parameter means like "target color". So, if you want to track blue people,
you can change upper code like this.
Xrgb_trgt = [0; 0; 255];
But if you set "green" as "target color", you might face a small problem.
In this webinar, our engineer is trying to track green ball, and showing how he solved his problem.
In some cases, using other color space like HSV might be another solution.
could you tracking the other color such as green color or yellow or blue.
on that case, which parts of the code should be change.
Thank you very much for your feedback. Even though research of image processing is not my main job, but if you create some interesting application, please let me know.
I hope your project may go well.
I think that you used the exp() in the resampling function to convert the -Inf values of L() to zero. If you didn't convert these values, when you make Q, you will obtain a NaN values. Tahnks a lot for your cooperation.
If you are interested by the image processing and video processing we can work in cooperation. happy weekend.
I think I need "exp" to convert log likelihood to real value.
You might not need "exp" when you input real value to resampling function.
Anyway, I'm glad your problem seems to be solved.
thanks a lot,
really my problem is in the resampling task, when w e change the likelhood distance. I used the intersection between histogramme to determine the likelhood for each particle but in the resampling task. I think that you must change the first line of your programm exp(L-max(L)) by L-max(L). Thanks
Because I'm not an expert of image processing, I might not be able to give you the best advice of this area.
But I have a few general advice which I can think of. I hope these comments may become your help.
1. Start with the simplest case
Maybe you can simply start with changing the target color from red to skin color,
and check if my program works with your skin color or not.
And after that, you can evolve the algorithm to detect the orientation of face.
If you know the ceter location of face, it's going to be easier to detect the orientation of face.
Maybe you can create some face images rotated 0, 45, 90, 135,or 180 degree, then you might can find a good way (function) to detect the orientaion of the face.
2. Basic attitude of algorithm development
I think the following web seminar might be useful for learning the basic attitude of alogrithm development. This is the another example of color tracking.
3. Face detection
What you want to do is face detection, you can find a good example in computer vision system toolbox.
I don't know the detail of this alogrithm, but I think this might to be the easiest way to detect a face :-)
I want to fit a square a round a face of a person. I consider each particle as a square and I added the square orienatation caracteristic the system of mouvemnt. Thus, I have, (position,speed,orientation). My problem is when I compare the histogram of the reference model and each particle using the distance of Bhattacharya and I do the resampling task, the result is very bad. Thus, I think that it is due to the result comparaison. Therefore, I used your method by modelate the color by gaussian but the result is also very bad. Please, have you any idea? thanks a lot.
Thank you very much for the compliments :-)
And your indication is right. "sigma" in my PDF document should be "sigma^2".
Thank you again for letting me know this mistake.
Hi, this is a great example (one of the best I have seen). There is just one correction, In PDF, Calculation of “likelihood” in likelihood, "sigma" should be out of square root or it should be sigma^2. One more time, great work!
Usually histogram's bins have equal width.
But when you use histc function, you can set the width of bins arbitrarily. For example, you can call this function like this.
Edge = [0 0.2 0.8 1]
Data = [ 0.1 0.3 0.5]
[~, I] = histc(Data, Edge)
And you get I = [1 2 2].
This means Data(1) belongs to 1st bin, Data(2) belongs to 2nd bin, and Data(3) belongs to 2nd bin(Please watch the help file ).
And I thought when I set
Edge -> (cumulative distribution)
Data -> (uniform random number from 0 to 1)
I thought I can do resampling of particles using histc.
I hope this explanation may help you.
I read some document and I found that there are several resampling method such as the systematic resampling. please which methods did you used? and normally, resampling stage aims to select the appropriate particles belongs to their weights but in your code I don't see this choice. thanks to expalin me more thgis fucntion.
The first two lines of resampling function are like this.
L = exp(L_log - max(L_log));
Q = L / sum(L, 2);
And this is same as this.
L = exp(L_log);
Q = L / sum(L, 2);
I subtract max(L_log) to maintain the precision of this type of calculation, because what's important is ratio Q.
please, can you explain me more the part of resampling and specially the first line.
Hi can I know from which paper does this project comes from?
I've translated the pdf slides which I used in my webinar. And I added them to my zip file.
This demo comes from the mathworks' webinar recorded in Japan.
Unfortunitely there's no English document right now. Sorry for the inconvinience...
You can watch webinar in Japanese.
Hi can I know from which paper does this project comes from?
I added English pdf-slides.
I added some PDF-slides which explain object tracking using particle filter.
I added the URL of web seminar about particle filter.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.