SingleMolecule / iSBatch

Hierarchical batch plugin for ImageJ
http://singlemolecule.github.io/iSBatch/
1 stars 1 forks source link

Macro Panel #3

Closed vcaldas closed 9 years ago

vcaldas commented 9 years ago

Macro panel should behave as follows:

If the user provides a customName, it overrides the Tags in the combobox.(when searching)

If tables and ROIS are generated with this macro, the difference is in the extension. [green]514.tif input. output [green]514[custom].tif | [green]514[custom].roi |[green]514[custom].zip |[green]514[custom].table table is a csv file.

cmpunter commented 9 years ago

Maybe what would help is an example macro. Can you give a few macro-examples? Also specify where the output should be specified.

vcaldas commented 9 years ago

Use a macro recorder with any random operations and try to reproduce it.

One example could be:

run("Delete Slice"); run("Delete Slice"); run("Delete Slice"); run("Peak Finder", "use_discoidal_averaging_filter inner_radius=1 outer_radius=3 threshold=6 threshold_value=0 selection_radius=4 minimum_distance=8 stack"); run("Select All");

roiManager("Measure");

This example takes a image, alterates the image. Creates a ROI manager and a ResultsTable. So, all should be saved and the code starts with a single open image.

cmpunter commented 9 years ago

Clear! So the there will be three files that need to be saved. The original file (but now with a tag). The results table and all the roi's of the roiManager. Is this correct?

vcaldas commented 9 years ago

Yep. In this case yes. I think it is fair to assume this to start. And the user has to indicate the tag! I'm currently assuming that the names follow [channel]name_tag.tif , [channel]name_tag.zip (for the rois) and [channel]name_tag.csv for the table.

vcaldas commented 9 years ago

To avoid future problems. Leave the option in the dialog to call one image, one ROI Manager and one table. If the user dont specify anything, then it won't be previously open. I think this covers most of the usual cases.

cmpunter commented 9 years ago

It will be difficult to check if the macro created multiple images! The easy way is

IJ.open("Z:\\Victor\\PollymeraseCompetition\\PolymeraseCompetition\\TimeLapse\\DnaX_UmuC_001\\001 514.TIF");
String macro = "IJ.log(nImages);run(\"Gaussian Blur...\", \"sigma=2 slice\");";
IJ.runMacro(macro);
ImagePlus imp = IJ.getImage();
System.out.println(imp.changes);

So you can open an image, then run a macro on it and get the result (and check if the image was changed!).

Is this sufficient? Or do we need support for multiple images? I'm writing a wrapper MacroRunnerclass for this.

vcaldas commented 9 years ago

Why don't you use a WindowManager.getImageCount() or WindowManager.getImageNames()? Then you can check if images were created and save all of them. Or even compare the names that existed before and the ones created later.

The wapper sounds a great idea! Did you try using the already built in imageJ macro? IJ.run("Macro... ", "output=TIFF file=[] text1=[run("Subtract...", "value=207 stack"); ]");

So probably we will have to wrinte a Files[] as input and it will likely to be done!

cmpunter commented 9 years ago

There is a problem with using WindowManager.getImageCount() and WindowManager.getImageNames(). When a macro is ran on an image then WindowManager.getImageCount() will correctly return 1. When the macro duplicates the input image you would expect two images. This is, unfortunately not the case :

IJ.open("Z:\\Victor\\PollymeraseCompetition\\PolymeraseCompetition\\TimeLapse\\DnaX_UmuC_001\\001 514.TIF");
String macro = "IJ.log(nImages); ";
IJ.runMacro(macro);
System.out.println(IJ.getImage());

for (String title : WindowManager.getImageTitles()) {
    ImagePlus i = WindowManager.getImage(title);
    System.out.println(i);
}

Correctly outputs :

1
img[001 514.TIF (512x512x1x1x1)]

But when the macro code opens other images:

IJ.open("Z:\\Victor\\PollymeraseCompetition\\PolymeraseCompetition\\TimeLapse\\DnaX_UmuC_001\\001 514.TIF");
String macro = "IJ.log(nImages); run(\"Duplicate...\", \"title=test1\"); run(\"Duplicate...\", \"title=test2\");";
IJ.runMacro(macro);
System.out.println(IJ.getImage());

for (String title : WindowManager.getImageTitles()) {
    ImagePlus i = WindowManager.getImage(title);
    System.out.println(i);
}

The output is :

1
img[test2 (512x512x1x1x1)]
img[test1 (512x512x1x1x1)]
img[test2 (512x512x1x1x1)]

This means that there is no reference to the original input image even though that image might have been manipulated.

cmpunter commented 9 years ago

A quick fix is to open the input image inside the macro code. So an open-statement will be appended to the macro code (as a prefix of course).

String path = "Z:\\Victor\\PollymeraseCompetition\\PolymeraseCompetition\\TimeLapse\\DnaX_UmuC_001\\001 514.TIF";
path = path.replace("\\", "\\\\");  // necessary since it will be included in the macro code
String macro = "IJ.log(nImages); run(\"Duplicate...\", \"title=test1\"); run(\"Duplicate...\", \"title=test2\");";
IJ.runMacro("open(\"" + path + "\");" + macro);
cmpunter commented 9 years ago

I just added the new macro runner. Please take a look at the macro runner class. This class contains all the logic for running macros. Especially the node filter is important since it decides which fileNodes will be considered for running a macro on. Also take a look at the runMacro method since this method contains all the logic for storing files.

cmpunter commented 9 years ago

By the way, I changed the Importer class slightly!

public void importFile(Node node, File file, String channel, String name) {

I removed the last argument path since this one is anyway taken from the File object that you supply. This also involves a little change in the FlattenOperation class since it uses this method,

cmpunter commented 9 years ago

Output folder option. So output all files to a specified folder instead of the default output folder. The files should not be included in the tree when a output folder is specified!

cmpunter commented 9 years ago

I've added the output folder option. This has been tested.