Intensity profile along a line, for a z-stack

Hello friends,
I need to automate the following:

  1. Select a z-stack tif image.

  2. Go through all the slices one by one in a loop.

  3. For each slice, draw a straight line of a constant thickness ‘t’ pixels. I don’t have information about the end-points in advance so I can’t use makeLine. This needs to be done on the fly.

  4. Measure intensity profile across the line, save it as a .csv file (for each slice separately).
    From the above, I am able to automate step 1, 2 and 4. But that’s for a pre-drawn line, common for all z-slices.

    stack1 = getImageID;
    n = nSlices;
    for (i=1; i<n; i++) {
    showProgress(i, n);
    profile = getProfile(); //run(“Plot Profile”);
    lt = profile.length;
    for (j=0; j<lt; j++)
    {setResult(“Value”, j, profile[j]);}
    path = getDirectory(“home”)+“profile_slice”+ i + “.csv”;
    saveAs(“Results”, path);

However, I can’t find how to do step 4 i.e. drawing a new line for the profile (or modify the previous one) for each newly opened z-slice.

Can someone kindly help? Thanks in advance!!

Hi Frodo,

Welcome to the forums!

Maybe you are looking for something like this:

Halts the macro and displays string in a dialog box. The macro proceeds when the user clicks “OK”. Unlike showMessage, the dialog box is not modal, so the user can, for example, create a selection or adjust the threshold while the dialog is open. To display a multi-line message, add newline characters ("\n") to string. This function is based on Michael Schmid’s Wait_For_User plugin. Example: WaitForUserDemo.

Using this function you can halt the macro at a particular point, define a new line selection and then press “OK” to continue.

Hello 7rebor,

Thanks a ton for your reply! :smiley: Now in retrospect I feel this was such an easy thing to do but I couldn’t because I am new to macros!

Anyway, for now I think my problem is solved. Thanks again!

No problem, we all have to discover it some way! You can mark posts as a solution (bottom right - tick mark) so the thread is marked as solved on the main page of the forum.

EDIT: You can find built in macro functions listed on this web page, very handy for anything you can’t capture using macro recorder!

1 Like