Showing posts with label tracking. Show all posts
Showing posts with label tracking. Show all posts

Saturday, March 17, 2012

Count on your neighbour

Counting how many stuff you have is important
Scrooge counting his money
... but boring
counting sheeps
During last week, I saw a few times one of my fellow lab member printing a picture like this
Phase contrast microscopy picture of nucleation
and putting a cross on each white object. He was counting them. The first time I saw this, I thought he had to do it for one or two pictures. But at the end of the week, I asked him what he was doing and if I could help.


The above picture is taken when a phase A nucleates into a phase B. This appends for example if you cool a liquid below it's crystallization temperature. A crystal nucleus will appear from time to time and grow. The probability to form a nucleus (nucleation rate) is a very important physical parameter: if nucleation is extremely rare, you will have a single nucleus in you bottle that will grow to form a single crystal before the birth of the next nucleus. This is exactly what you want for example when you make a silicon wafer for microelectronics. If nucleation rate is high, then you will have many nuclei growing at the same time and at the end a material that is made of many different crystals. You may want this in ice creams, because small crystals have a more pleasant texture than big ones.




The only method to measure the nucleation rate in a given system is to count the number of nuclei function of time. So my colleague was counting ... for the whole week. He had done two dozens of experiments at different temperatures and compositions, and took a series of picture for each (like every couple of second for a few minutes). This makes hundreds if not thousands of pictures to analyze. And his plan was to do it by hand.

Try to count how many nuclei are in the above picture. This is a task that need careful attention: large nuclei have a good contrast, but there are many smaller ones very difficult to tell from the background. That's why my colleague was printing and crossing the counted nuclei.

As I told you in a previous post, this kind of procedure can be fully automatized. The programming takes time, so if you have only a few pictures to analyze, this may not be a good idea. In addition, this counting is tricky because the objects can have very different sizes and contrasts. However I, sitting 3 steps away, had already developed and tested such a program. The physical signification is different (I am tracking polydisperse colloidal particles) but the technology is the same. So yes, I could help.

An hour later my colleague had in his computer a script counting the nuclei for him, a picture per second or less, automated to treat a whole time series automatically without human intervention. Setting-up Python and dependencies on his computer took half of the time. We should have communicated earlier, before he had spent a week doing what the script could do in an hour.

Result of the localization. Original image (red) superimposed with localized positions (cyan squares)
As you can see on the picture above, the result is not 100% perfect, but quite close. For example there are problems when nuclei are fusing and there are also (very few) centers counted multiple times. I think I know how to adapt better my program to this situation, but my colleague told me it was enough precision for him.

This gives an other motivation to explain (in a future post) how this counting/localizing method is working.

Wednesday, November 16, 2011

Particle tracking I : from analog to digital


Pinpointing the positions and sizes of tens of thousands particles from pictures. I can't miss one, I can't detect a particle where there is none. The precision must be extremely high. That is what I am doing routinely as the basis of my research. If I don't get this step right, my research has feet of clay, standing on sand.

In 1905 Einstein published three papers founding or revealing three different fields of physics : relativity, quantum mechanics and Brownian motion. The last one is a major breakthrough in statistical physics because if it was true, then matter was discontinuous, made of particles like atoms or molecules. However an experimental proof was needed.
Jean Baptiste Perrin

Jean Perrin exhibited this proof by the following experiments around 1908 : he suspended microscopic gamboge particles in water and waited for them to settle. Obviously their were more particles at the bottom than at the top ; however, how many more ? Perrin took a microscope and counted : how many particles do I see in average in a drop of suspension taken at 1 cm from the bottom (do it for 1000 drops to get a good average) ? How many at 2 cm ? etc. The concentration profile he got was perfectly fitting with theoretical predictions and thus discontinuity of matter was proved. Jean Perrin got the Nobel prize in physics 1926 for that.

A century later, how do you do track particles ? First, you don't need to stick your eye to a microscope. You take a digital picture with a CCD camera adapted to the microscope. Of course you can take movies.
A typical image of a dense colloidal suspension, taken by confocal microscope.
Now you have about ten thousand pictures like that out of a single experiment. Of course, you can superimpose the picture with a grid, locate the coordinates of a particle by following the grid with your finger, write them down in a notebook and so on and so forth. Perrin could have done that during years, but we have computer slaves.

Crocker and Grier designed the following algorithm to track individual particles from pictures. It is probably easier to understand if we imagine the intensity of each pixel as an altitude. For example, the two pictures below are equivalent.

Noisy picture of particles
Corresponding intensity profile
Blur your image to remove noise and to smooth the particles' intensity profile. Each particle should become a peak with no flatness at the top.

Previous picture, blurred


Find the pixels that are local intensity maxima. Their must be one per particle + others due to noise.
Local maxima


If you have large areas without particles, you may find local maxima there due to noise. If you remove the local maxima that are not bright enough, you should be left with only particles, none from noise. Now you know the coordinates of each particle centre with discreet (pixel) precision.
To increase the precision, you can take the centre of mass (intensity) of the pixels surrounding each possible centre. This gives subpixel resolution (about 1/10th of a pixel).

This is an extremely quick and efficient algorithm used routinely by many groups either in 2D or in 3D (yes, you can take 3D pictures, I'll have a post about it). You can check the official web page for more information. My own code for that is on sourceforge.

So far so good if your particles have the same size ... something that almost never append in nature, and not that often in experiments. I'll write about the more-than-one-size case in an other post.