How to do a macro to save automatically an image using as a file name only some of the words from the original title

Dear all, I have this macro to open in Fiji one .lif file

s = 4;
run(“Bio-Formats Importer”, “open=[C:/image_123 T0.lif”] autoscale color_mode=Composite split_channels view=Hyperstack stack_order=XYCZT series_"+s);

Then I correct my image and I want to save it in the same folder but with the name “T0_mtq2.tiff”.

If I would have only 1 image I would do manually, but I have 100 (T0, T15, T23…), that I have to open correct and save. I would like to avoid typing manually the names. So it is any way to write in the macro some code, so the moment an image is loaded, Fiji recognizes the title and save the file updating the filename according with the original´s file name?

Thanks

Hi Miguel,

Use this:

FileName=File.nameWithoutExtension -; //Fiji recognises the file name
SaveAs(“tif”, outDir+"_mtq2.tiff"); //Fiji saves the file in the directory you have chose (outDir) and the file name is amended with “_mtq2.tiff”.

M.

1 Like

So sorry, my bad, I made a mistake in my explanation. First I open a file using Bio-Format importer. This file contain 4 different stacks (4 different channels). For each channel I want ImageJ to safe an image using par of the window name.

E.g.
File name: “confocal test”
Window 1: mitocondria tracking_Pos2_C=0
saveas( tif., Pos2_mtq2)
Window 2: mitocondria tracking_Pos2_C=1
saveas( tif., Pos2_rfp)
Window 3: mitocondria tracking_Pos2_C=2
saveas( tif., Pos2_yfp)
Window 4: mitocondria tracking_Pos2_C=3
saveas( tif., Pos2_gfp)

Then I will open another serie from file “confocal test”. And I want to save again 4 images but in this case for Pos3, then Pos4, and so on…

I was wondering if I could write a macro so I do not have to change every time the name of the positions, the idea is that ImageJ recognize the position and the channel of each window.

Thanks.
Miguel

Yes, roughly…

if (!endsWith(path,"/")) open(path); // if subdirectory, push down into it Still have to open Path
t=getTitle(); // gets the name of the image being processed
while (nImages>0) {
FileName=File.nameWithoutExtension -; //Fiji recognises the file name
SaveAs(“tif”, outDir+"_mtq2.tiff")
close();
}

Thank you very much
Best regards,
Miguel