Defining images to be used in a plugin_Macro

I got some help to define the images to be pre-processed:

Now I would like to run a plugin to identify the objects that overlap in several channels. This script opens them but I can’t get how to define them in the plugin and save the pooled results later. I would really appreciate some help.

May be this can help.

// Get the folders first
#@File directory (style=“directory”);

subfolders = getFileList( directory )

// Go through each folder
for ( i=0; i<subfolders.length; i++ ) {
// Check that it is a folder
if ( endsWith( subfolders[i], “/” ) ) {
//Open sub images
image_name = substring( subfolders[i] , 0, lengthOf( subfolders[i] ) -1 );

	// Open object images here
	open(directory + "/" + subfolders[i] + image_name + "CH2_objects.tif");
	open(directory + "/" + subfolders[i] + image_name + "CH4_objects.tif");
	run("Binary Feature Extractor", "objects= directory + "/" + subfolders[i] + image_name + "Iba1_objects.tif" selector=directory + "/" + subfolders[i] + image_name + "DAPI_objects.tif"_overlap=30 count"); //extract double positive objects with overlap 30%
	run("Binary Feature Extractor", "objects= Here I want to add the results of the first binary feature (file starts with extracted)" selector=directory + "/" + subfolders[i] + image_name + "CH3_objects.tif"_overlap=20 count"); //extract Triple positive objects with overlap 20%
	Then I want to save the pooled results of the count including the image label to be able to identify it.
}
}

Hi @OmarMossad,

you can access images and assign them to parameters of plugins using variables and the the getTitle() method.

I’m not 100%ly sure about your input images, but the code may look more or less like this:

// Get the folders first
#@File directory (style=“directory”);

subfolders = getFileList( directory )

// Go through each folder
for ( i=0; i<subfolders.length; i++ ) {
    // Check that it is a folder
    if ( endsWith( subfolders[i], “/” ) ) {
        //Open sub images
        image_name = substring( subfolders[i] , 0, lengthOf( subfolders[i] ) -1 );

        // Open object images here
        open(directory + "/" + subfolders[i] + image_name + "CH1_objects.tif");
        first_image = getTitle();
        print("First image: " + first_image);
        open(directory + "/" + subfolders[i] + image_name + "CH2_objects.tif");
        second_image = getTitle();
        open(directory + "/" + subfolders[i] + image_name + "CH3_objects.tif");
        third_image = getTitle();
        open(directory + "/" + subfolders[i] + image_name + "CH4_objects.tif");
        fourth_image = getTitle();
        
        run("Binary Feature Extractor", "objects=" + first_image + " selector=" + second_image + " overlap=30 count"); //extract double positive objects with overlap 30%
        run("Binary Feature Extractor", "objects=" + third_image + " selector=" + fourth_image + " overlap=20 count"); //extract Triple positive objects with overlap 20%

        // save table
        saveAs("measurements", "C:/temp/results.xls");
    }
}

Let us know if it works!

Cheers,
Robert

1 Like

Hi @haesleinhuepf,

Thank you for your time.

It doesn’t work totally. I had to add a close all run("Close All"); before saving. It goes through all the images and saves the first image in the log but I get an exception window with the following error.

The results file is just having the error text but if I add strings to “first_image” and further to test, the results file is ok but of course stops after the first set and says the images can’t be repeated.

(Fiji Is Just) ImageJ 2.0.0-rc-69/1.52p; Java 1.8.0_172 [64-bit]; Windows 10 10.0; 313MB of 9096MB (3%)
 
java.lang.NullPointerException
	at Binary_Feature_Extractor.run(Binary_Feature_Extractor.java:92)
	at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:266)
	at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:114)
	at ij.IJ.runUserPlugIn(IJ.java:232)
	at ij.IJ.runPlugIn(IJ.java:193)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:63)
	at ij.IJ.run(IJ.java:312)
	at ij.IJ.run(IJ.java:323)
	at ij.macro.Functions.doRun(Functions.java:624)
	at ij.macro.Functions.doFunction(Functions.java:97)
	at ij.macro.Interpreter.doStatement(Interpreter.java:275)
	at ij.macro.Interpreter.doBlock(Interpreter.java:671)
	at ij.macro.Interpreter.doStatement(Interpreter.java:320)
	at ij.macro.Interpreter.doIf(Interpreter.java:1049)
	at ij.macro.Interpreter.doStatement(Interpreter.java:296)
	at ij.macro.Interpreter.doBlock(Interpreter.java:671)
	at ij.macro.Interpreter.doStatement(Interpreter.java:320)
	at ij.macro.Interpreter.doFor(Interpreter.java:593)
	at ij.macro.Interpreter.doStatement(Interpreter.java:302)
	at ij.macro.Interpreter.doStatements(Interpreter.java:261)
	at ij.macro.Interpreter.run(Interpreter.java:157)
	at ij.macro.Interpreter.run(Interpreter.java:91)
	at ij.macro.Interpreter.run(Interpreter.java:102)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
	at ij.IJ.runMacro(IJ.java:148)
	at ij.IJ.runMacro(IJ.java:137)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1108)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1104)
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:1055)
	at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1104)
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:147)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)```
2 Likes

Ok, I’m unfortunately not an expert regarding the “Binary Feature Extractor” plugin let’s see if Jan @biovoxxel can help us :wink:

Hi @OmarMossad,

I will have a look at your macro. I am sure the error just occurs because an image is missing. I will get back to you asap

1 Like

I guess that the main problem is that you try to run the Binary Feature Extractor on an original image without any prior thresholding to make it binary. That is a necessary step. The Binary Feature Extractor only takes 2 binary images as input. Besides that, as indicated in the corrected macro by @haesleinhuepf you will need to take care of the quotation marks to integrate variables correctly into recordable methods of ImageJ/Fiji