ImageJ Macro run file in the order 1, 2 ,3,4, 5.. instead of 1, 10, 11, 12, 2, 21

Dear all,
I create a IJmacro to analyze my files.
The name of my files are: 1.ome.tif, 2.ome.tif etc…
I would like to analyze my data 1, 2 ,3, 4, 5… instead of 1, 10, 11, 12, 2, 21 or do you know how to do that with Excel? Because Excel considered the name 1.ome.tif as a name and I didn’t find a way to sort my data.

best,

The code to open the data look like this

list = getFileList(input);   

for (i=0; i<list.length; i++) {
	if (endsWith(list[i],".ome.tif")){
	inputPath= input + list[i];
    open(inputPath);

Just another thought would be to use the Import->Image Sequence... which can sort the files numerically, with end patterns, and recorded with the macro recorder, too, see:

https://imagej.nih.gov/ij/docs/guide/146-26.html#toc-Subsection-26.6

1 Like

It is much more convenient to always name your files so they start with 0s: 001.ome, 002.ome and so on.
Another issue I tend to avoid is using spaces in file names.
There are some handy file renaming programs. I use krename in linux:
https://userbase.kde.org/KRename

2 Likes

Even with the import Image sequence… I can’t find a wait to open image 1 process it and analyse particles, close and then open image 2 it open always image 11.
Could you show me an example of loop with image sequence tool?

And do you know how to modify the name of the file in a macro ?
I explain I use NDPItools plugin and it add to my file name _x10_z0_1 usually I use name = getTitle(); and I add infos like xx_x10_z0_1_preprocess and I save my file and then I open again to continue the macro because the first part need a human interaction but not the second part and I would like to save the mask with only the name xx_preprocess or xx

If you drag the folder with the files on ImageJ or (use the import image sequence action by selecting one file - momentarily I use Windows) a dialog pops up to import the sequence as a stack or virtual stack.

I have to enable the option “Sort names numerically” and then the sorting is:

“Sort Names Numerically” When checked, the stack will be opened in numeric file name order (e.g., ‘name1.tif’, ‘name2.tif’, ‘name10.tif’) instead of alphanumeric order (e.g., ‘name1.tif’, ‘name10.tif’, ‘name2.tif’)…

I renamed some example files and it worked for me numerically - to use the terms of the documentation.

Now I can simply iterate over the stack and can make my measurements.

Simple example:

https://imagej.nih.gov/ij/macros/Measure_Stack.txt

So you can select stack image 1, make your measurements and then save the image
individually with a new name.

If you need human interaction after saving the image even that is possible with a stack (after setSlice() - see example).

See, e.g.:

http://imagej.1557.x6.nabble.com/saving-images-from-a-stack-td4998795.html

And more examples here:

https://imagej.nih.gov/ij/macros/

API documentation:

https://imagej.nih.gov/ij/developer/macro/functions.html

For a wait dialog, see:

https://imagej.nih.gov/ij/developer/macro/functions.html#W

2 Likes