For loop(ROI measurement every time frame) in Macro

In the image file, it has 170 time frames. At first frame, you can find the brightest particle in the image. In my script, it shows us the particle measurement in the end.
I want to get this result over time. Because the particle moves slightly, it needs to redetect new ROI over time. Finally, I would like to plot intensity over time.
But I don’t know what to do. Could you guys give me some advice about that?

sample.tif (13.9 MB)

for(s = 1; s<nSlices(); s++){

originalImageID = getImageID();
run("Duplicate...", "duplicate");

run("Gaussian Blur...", "sigma=2 stack");
setAutoThreshold("Default dark");
setThreshold(13337, 65535);
run("Create Mask");
run("Analyze Particles...", "size=10-Infinity exclude add");

run("Clear Results");

Hello Jae -

In a general sense, you want to track your particle. There are
a number of tracking plugins available for Fiji / ImageJ. (See
Plugins > Tracking for some of those that ship with Fiji.)

In your case, you only care about the one particle, and that particle
really doesn’t move very much. So you might be able to use a
“poor-man’s tracking algorithm.”

Roughly: Either you or a simple algorithm locates the brightest
ROI in the first frame. You record its location. In each subsequent
frame, you identify the the ROI closest to that location and deem
it to be your particle. (Or you might find the ROI closest to the
location in the previous frame, rather than in the first frame. But
in your sample stack, it doesn’t look like it will matter.)

You then calculate the average brightness for each slice’s chosen

One fly in the ointment: To my eye, the particle disappears
sometimes – particularly in frames 9 and 10. Also, when I run
your Threshold / Analyze Particles... macro on your stack,
it also appears not to detect your particle in frames 9 and 10.
So you probably need to account for frames in which the particle
is simply not visible.

It might work to simply require that your tracked-particle ROI be
within a certain distance of its target location, and if no ROI is
close enough, deem the particle to not be visible in that frame,
and go on to the next frame. I guess you would set the measured
brightness to zero for such frames.

Whether you use an existing tracking plugin or go down this path,
feel free to show us partial results and ask further questions if
issues arise.

Thanks, mm

1 Like