1
$\begingroup$

I'm attempting to track the position of two particles by recording a .tiff file of their visual movement under a microscope. I use Mathematica to Binarize with a high enough threshold so that only the particles' position is visible and then I negate the color so that it's black dots on a white background. After doing this, my professor helped me set up some code to analyze the matrix of the tiff file to find the position among the 1s and 0s, and then I mapped this out to create an animation of its movement. I've been trying to use the same code to analyze two particles, but I'm not sure what I would need to change to do so. The code for one particle is listed below:

images = Import["images.tif"];
Length[images]

{images[[1]], images[[2]]}
images[[1]]
Binarize[images[[1]]]
Binarize[images[[1]], .6]
ColorNegate[Binarize[images[[1]], .6]]

newimages = {}
For[i = 1, i <= Length[images], i++, 
 AppendTo[newimages, ColorNegate[Binarize[images[[i]], 0.6]]]]
Table[N[Position[ColorNegate[Binarize[images[[i]], .6]] // ImageData, 
    0] // Mean], {i, 1, Length[images]}]
N[Position[ColorNegate[Binarize[images[[1]], .6]] // ImageData, 0] // 
  Mean]
ListLinePlot[
 Table[Position[ColorNegate[Binarize[images[[i]], .6]] // ImageData, 
    0] // Mean, {i, 1, Length[images]}], 
 ColorFunction -> "SunsetColors", ImageSize -> 300]

Please let me know if I need to provide anything else. I tried to run the exact same code with the two particles images just to see what would happen, and as expected, the images binarized fine, but the positions couldn't be found. I'm just using a sample .tiff for the two particles which is the exact same two images in a single .tiff file and on the return matrix, it gives: {{324.127, 454.076}, {324.127, 454.076}}. This leads me to believe that the code just finds the mean value of any 0s, not clusters of 0s, which gives a mean movement of the two particles combined instead of the movement of the two particles separately. How could I alter the code to analyze clusters of 0s instead of the mean of 0s over the entire picture?

Edit: Here's a picture of the two particle picture. picture of two particles

And here it is again after binarized. binarized two particles

And finally after the threshold of binarize is increased and the picture is color negated. negated two particles

This is the output of the matrix for one particle:

{{426.5, 634.41}, {427.351, 635.519}, {427., 635.382}, {426.545, 
  634.545}, {428.974, 634.558}, {428.128, 635.615}, {427.513, 
  636.4}, {429.481, 635.649}, {429.367, 635.367}, {430.09, 
  634.436}, {427.722, 635.443}, {426.88, 636.64}, {425.903, 
  635.167}, {427.385, 634.872}, {426.04, 634.333}, {426.795, 
  635.59}, {425.623, 636.623}, {427.658, 636.177}, {427.779, 
  637.221}, {426.77, 636.149}, {427.493, 635.773}, {427.395, 
  635.566}, {427.707, 635.84}, {427.297, 635.095}, {427.697, 
  635.776}, {428.584, 636.857}, {429.38, 636.063}, {429., 
  636.932}, {428.234, 636.468}, {426.697, 635.276}, {426.658, 
  636.316}, {427.753, 634.753}, {428.125, 633.5}, {428.342, 
  633.823}, {427., 635.618}, {427.513, 636.526}, {427.26, 
  636.273}, {427.385, 636.128}, {428.182, 635.779}, {430.182, 
  634.649}, {427.182, 635.351}, {426.901, 634.099}, {426.5, 
  633.41}, {429.238, 634.675}, {428.68, 633.987}, {426.917, 
  635.014}, {426.905, 636.703}, {426.973, 636.44}, {429.118, 
  633.658}, {428.697, 635.776}, {428.455, 634.455}, {428.526, 
  634.605}, {426.197, 637.289}, {429.443, 636.899}, {429.053, 
  635.653}, {428.59, 635.795}, {429.286, 635.286}, {428.364, 
  635.247}, {427.605, 633.474}, {428.132, 635.5}, {428.197, 
  633.289}, {427.545, 633.545}, {427.347, 635.053}, {428.342, 
  637.823}, {428., 636.5}, {428.233, 636.082}, {427.545, 
  635.545}, {427.595, 635.081}, {429.545, 633.545}, {429.307, 
  637.16}, {427.24, 636.24}, {428.027, 636.56}, {429.027, 
  635.56}, {427.043, 635.943}, {427.143, 636.325}, {428.4, 
  635.8}, {427.753, 635.636}, {430.125, 637.5}, {428.753, 
  634.636}, {429.41, 634.205}, {427.382, 634.}, {428.303, 
  636.224}, {428.434, 636.605}, {428.182, 637.351}, {428.532, 
  636.766}, {428.519, 635.351}, {427., 635.689}, {428.944, 
  636.958}, {428.342, 637.118}, {427.692, 635.615}, {428.5, 
  635.231}, {428.767, 634.918}, {428.364, 636.247}, {429.5, 
  635.821}, {428.143, 635.325}, {426.316, 635.605}, {428.76, 
  635.76}, {428.903, 634.833}, {428.276, 635.697}, {426.481, 
  635.558}, {427.937, 634.519}, {429.385, 634.872}, {428.973, 
  636.44}, {428.308, 635.769}, {429.377, 635.364}, {429.653, 
  637.053}, {429.605, 635.566}, {429.618, 636.}, {429.88, 
  635.64}, {427.767, 634.89}, {428.844, 635.442}, {428.065, 
  635.377}, {428.081, 636.527}, {428.973, 638.123}, {428.385, 
  635.872}, {426.5, 635.757}, {427.44, 636.973}, {427.507, 
  635.227}, {428.392, 635.311}, {427.784, 634.703}, {428.76, 
  635.76}, {427.356, 635.123}, {428.395, 636.434}, {428.545, 
  634.545}, {428.615, 634.692}, {428.684, 637.395}, {428.903, 
  636.833}, {427.618, 636.}, {428.162, 636.5}, {429.095, 
  635.297}, {427.347, 636.947}, {428.203, 635.405}, {427.377, 
  634.935}, {428.5, 635.868}, {427.806, 635.028}, {427.097, 
  635.167}, {426.342, 635.096}, {427.167, 633.903}, {427.616, 
  635.247}, {427.356, 635.123}, {426.608, 634.689}, {426.932, 
  635.716}, {428.148, 634.556}, {431.32, 636.987}, {429.527, 
  637.081}, {430.675, 635.857}, {430.627, 636.173}, {428.903, 
  636.167}, {428.76, 635.76}, {426.833, 634.903}, {428.408, 
  636.079}, {428.233, 636.082}, {428.833, 634.903}, {428.5, 
  636.5}, {429.253, 634.96}, {429.689, 635.365}, {428.943, 
  634.957}, {429.027, 635.56}, {426.521, 635.877}, {429.128, 
  634.5}, {429.56, 634.853}, {427.919, 635.405}, {426.36, 
  634.12}, {429.043, 637.057}, {430.423, 636.218}, {427.836, 
  635.164}, {428.921, 636.408}, {427.903, 635.833}, {427.405, 
  636.797}, {429.297, 634.216}, {427., 636.}, {428.321, 
  633.718}, {429.097, 635.417}, {428.943, 634.957}, {428.901, 
  634.901}, {428.622, 634.892}, {430.392, 634.311}, {429.419, 
  636.324}, {428.097, 637.167}, {428.56, 636.48}, {428.558, 
  635.844}, {427.901, 635.901}, {429.77, 634.824}, {429.194, 
  635.972}, {429.958, 637.127}, {429.23, 637.419}, {428.5, 
  636.162}, {427.486, 635.819}, {427.097, 637.417}, {428.056, 
  636.887}, {428., 636.5}, {429.099, 635.099}, {427.562, 
  634.137}, {428.384, 636.247}, {428.293, 636.4}, {430.467, 
  635.187}, {429.423, 635.603}, {429.043, 637.057}, {426.931, 
  635.597}, {429.75, 636.447}, {428.901, 636.901}, {428.844, 
  637.442}, {427.833, 635.097}, {427.64, 635.12}, {428.595, 
  634.919}, {429., 635.}, {428.083, 635.292}, {427.767, 
  634.89}, {427.634, 634.634}, {427.671, 634.329}, {426.562, 
  634.397}, {428.389, 634.819}, {429.081, 635.527}, {429.347, 
  636.053}, {429.438, 634.863}, {429.75, 635.5}, {428.648, 
  636.915}, {429.622, 636.284}, {428.389, 636.181}, {428.671, 
  635.671}, {427.466, 636.945}, {428.901, 635.155}, {427.671, 
  634.329}, {427.87, 635.029}, {428.5, 633.243}, {429.595, 
  633.919}, {427.901, 633.901}, {428.389, 634.181}, {428.44, 
  635.733}, {429.029, 635.314}, {428.5, 634.5}, {430.625, 
  635.625}, {429.581, 635.419}, {427.746, 633.944}, {426.87, 
  636.217}, {427.901, 637.901}, {428., 637.}, {428.611, 
  635.694}, {427.569, 635.708}, {428.306, 635.389}, {426.292, 
  634.431}, {428., 636.}, {429.167, 635.097}, {429.324, 
  635.831}, {428.901, 634.901}, {429., 635.}, {430.405, 
  636.027}, {428.812, 636.188}, {429.608, 636.595}, {428.806, 
  635.944}, {428.356, 634.562}, {430.74, 635.041}, {430., 
  635.}, {427.257, 634.714}, {428., 634.}, {427.043, 
  635.319}, {429.676, 637.169}, {429.778, 636.097}, {429.5, 
  635.5}, {429.736, 634.667}, {428.581, 634.419}, {429.986, 
  634.562}, {429.186, 635.929}, {428.306, 635.611}, {428.565, 
  633.522}, {429.297, 633.095}, {429.5, 634.}, {429.824, 
  636.77}, {430., 637.}, {430.814, 634.257}, {428.264, 
  636.139}, {427.528, 635.042}, {430.101, 634.942}}

And this is what the ListLinePlot of this matrix looks like: ListLinePlot

Also, the images I posted are all jpegs, but the tiff file is just a collection of 273 frames of images that look just like the jpeg. As far as I'm aware, the tiff files work really well for this process because .tiff is stored as a matrix which is perfect for tracking movement according to matrix values and no data is compressed in a .tiff, allowing for more precise tracking of movement.

$\endgroup$
1
  • 2
    $\begingroup$ 1) ask your advisor who helped you set up your current code? 2) include at least one example of a tiff file with the two particles. $\endgroup$
    – MarcoB
    Commented Sep 16, 2022 at 2:09

1 Answer 1

1
$\begingroup$

One could use FindClusters as follows:

(* load image posted by OP *)
image=Import["https://i.sstatic.net/u7Ufw.jpg"]; 

(* compute two positions *)
data=Position[ImageData[ColorNegate[Binarize[image,.6]]],0];
N[Map[Mean,FindClusters[data,2,Method->"Optimize"]]]

This gives

{{301.,402.},{344.5,499.952}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.