Filename for generic macro

Hi,

I’m totally new to this image analysis and macros and I have some trouble…

This is the macro I have come up with so far by using the macro recorder:

// Split image into red, green and blue channels
run("Split Channels");

// Subtract red channel from green
imageCalculator("Subtract create", "Image 1_m01.tif (green)","Image 1_m01.tif (red)");
selectWindow("Result of Image 1_m01.tif (green)");

// Threshold
setAutoThreshold("Default dark");
//run("Threshold...");
//setThreshold(50, 255);
run("Convert to Mask");

// Close spheres
run("Close-");

// Count cells
run("Analyze Particles...", "size=30-Infinity circularity=0.45-1.00 show=Nothing display exclude include");

The problem is with the image calculator and make the macro generic so I can process a folder of images. I have tried batch process but the macro doesn’t work, and I have looked at


but I don’t understand it…

Can someone please help me finish this macro making it work?

Thanks in advance!

As explained on the link, you need to iterate over your set of images. For instance, if the images are stored in a folder, you would do something like this:

function action(input, output, filename) {
        open(input + filename);
        // Split image into red, green and blue channels--
        run("Split Channels");

       // Subtract red channel from green--
       imageCalculator("Subtract create", filename + " (green)", filename+" (red)");
       selectWindow("Result of "+filename+" (green)");

       // Threshold--
       setAutoThreshold("Default dark");
       //run("Threshold...");
       //setThreshold(50, 255);
       run("Convert to Mask");
       // Count cells--
       run("Analyze Particles...", "size=30-Infinity circularity=0.45-1.00 show=Nothing display exclude include");
}

input = "/home/fiji/input/";
output = "/home/fiji/images/";

list = getFileList(input);
for (i = 0; i < list.length; i++)
        action(input, output, list[i]);

Great, thank you! However, I saw I’ve missed an important thing in the:
run(“Analyze Particles…”, “size=30-Infinity circularity=0.45-1.00 show=Nothing display exclude include”);
It should be like this instead:
run(“Analyze Particles…”, “size=30-Infinity circularity=0.45-1.00 show=Outlines display exclude include summarize”);
Cause what I want is to have my cell count from each image summarized in a table, what do I need to add now?

Thank you!

Did you try to update the macro I sent you with the “summarize” option?

Yes, but no table is showing up…

Can you post here the image and the macro you are using?

The summary will show up at the end of the table and not in a new one.

This is what the image look like (and I have hundreds of images I want to analyze) and I want to do the following :

  1. Split the RGB channels
  2. Subract the red channel from green
  3. Threshold the resulting image
  4. Count the dots and collect the counts for each image in a table

I see, you need to replace these lines with the path where your data is:

input is the folder with your color images, output is not used in this case.

I’m sorry, but it still doesn’t work for me…

Is it not Process/Batch/Macro where I should run the macro? I put my image folder as “Input” and my new image folder in “Output”, open the macro and then click Process, but no table pops up… The only thing that happens is that the images from the input folder is copied to the output folder.

It is either…or:

  • The Process > Batch > Macro… command is an easy way to apply a simple macro to a bunch of images, but it is limited in its flexibility.
  • The procedure described in How to apply a common operation to a complete directory is an alternative way to achieve more flexible batch processing. The for loop takes care of processing each file in the given list. If you think some of the instructions on that page are difficult to understand, feel free to suggest improvements.

Regarding you macro from the first post, it is simple enough to be run with the first option (Process > Batch > Macro…). You just need to make the image names generic by using the getTitle() macro function to keep track of the current image title (e.g. in a variable named currentTitle):

currentTitle = getTitle();

// Split image into red, green and blue channels
run("Split Channels");

greenTitle = currentTilte + " (green)";
redTitle = currentTilte + " (red)";

// Subtract red channel from green
imageCalculator("Subtract create", greenTitle, redTitle);
selectWindow("Result of " + greenTitle);

// Threshold
setAutoThreshold("Default dark");
run("Convert to Mask");

// Close spheres
run("Close-");

// Count cells
run("Analyze Particles...", "size=30-Infinity circularity=0.45-1.00 show=Nothing display exclude include");

Now it works! Thank you so much!!! :smiley: :smiley: :smiley: