Discussion:
File import, sort names numerically not working.
Ved Sharma
2011-11-22 17:51:16 UTC
Permalink
Dear ImageJ users,

I'm trying import->Image sequence in a directory, which contains 44 files. File names are:

01_s1_t1.tif, ..., 01_s1_t11.tif
01_s2_t1.tif, ..., 01_s2_t11.tif
02_s1_t1.tif, ..., 02_s1_t11.tif
02_s2_t1.tif, ..., 02_s2_t11.tif

To import all the files containing "s1", I enter "s1" in the field "File name contains:" and check "Sort names numerically". But I find that the files ending with "t10.tif" and "t11.tif" do not appear after "t9.tif", rather they appear at the end of the stack. Is this a bug? Is there a better way to import these files?

I'm running ImageJ 1.46b5 on a Windows 7 machine.

Ved
Herbie
2011-11-22 17:59:19 UTC
Permalink
Post by Ved Sharma
Dear ImageJ users,
01_s1_t1.tif, ..., 01_s1_t11.tif
01_s2_t1.tif, ..., 01_s2_t11.tif
02_s1_t1.tif, ..., 02_s1_t11.tif
02_s2_t1.tif, ..., 02_s2_t11.tif
To import all the files containing "s1", I enter "s1" in the field
"File name contains:" and check "Sort names numerically". But I find
that the files ending with "t10.tif" and "t11.tif" do not appear
after "t9.tif", rather they appear at the end of the stack. Is this
a bug? Is there a better way to import these files?
I'm running ImageJ 1.46b5 on a Windows 7 machine.
Ved
What about using t09.tiff instead of t9.tiff ?

If this poses problems, then you might use a utility for batch
renaming files before you open them in IJ. I don't know about such
utilities for Windows but they must exist and most probably some of
them are free.

HTH

Herbie

------------------------
<http://www.gluender.de>
Rainer M. Engel
2011-11-23 09:57:24 UTC
Permalink
Post by Herbie
Post by Ved Sharma
Dear ImageJ users,
I'm trying import->Image sequence in a directory, which contains 44
01_s1_t1.tif, ..., 01_s1_t11.tif
01_s2_t1.tif, ..., 01_s2_t11.tif
02_s1_t1.tif, ..., 02_s1_t11.tif
02_s2_t1.tif, ..., 02_s2_t11.tif
To import all the files containing "s1", I enter "s1" in the field
"File name contains:" and check "Sort names numerically". But I find
that the files ending with "t10.tif" and "t11.tif" do not appear after
"t9.tif", rather they appear at the end of the stack. Is this a bug?
Is there a better way to import these files?
I'm running ImageJ 1.46b5 on a Windows 7 machine.
Ved
What about using t09.tiff instead of t9.tiff ?
If this poses problems, then you might use a utility for batch renaming
files before you open them in IJ. I don't know about such utilities for
Windows but they must exist and most probably some of them are free.
HTH
Herbie
------------------------
<http://www.gluender.de>
On Windows I would recommend these free tools..
http://www.bulkrenameutility.co.uk
or http://www.xnview.com/

Interesting read Norbert and I would second your suggestion.

regards,
Rainer
Norbert Vischer
2011-11-22 21:35:25 UTC
Permalink
The option "Sort Numerically" only picks the digits of the file name and concatenates them to a number. Then these numbers are sorted.
This behaviour has frequently created confusion also in our lab.

If you have this file list:

1a9.tif
1a10.tif
2a9.tif

the extracted and sorted numbers are 19, 29, 110 and result in:

1a9.tif
2a9.tif
1a10.tif



Wayne, my suggestion is that the filename would be split into an alphanumerical prefix and a purely numerical suffix. Then, prefixes should be sorted alphabetically, and only where they are equal ("1a" in the example), suffixes should sorted numerically.

The above sequence would then be sorted like this:
1a9.tif
1a10.tif
2a9.tif


Norbert Vischer
Research engineer
Centre for Advanced Microscopy
Swammerdam Institute for Life Sciences (SILS)
Science Park 904
1098 XH Amsterdam, the Netherlands
Ved Sharma
2011-11-23 17:40:45 UTC
Permalink
Hi Herbie,

Yes, changing the file name from t1.tif -> t01.tif helped me sort the files numerically. I realized that renaming can be done in ImageJ itself. So I wrote a little macro and I'm attaching it here(see below) if someone else wants to use it. Currently it is only doing two running digits, but can be easily extended to 3, 4 or more digits.

// start
macro "pad_zeros"{

dir = getDirectory("Choose a Directory");
filelist = getFileList(dir);

for (i=0; i<filelist.length; i++) {
if(endsWith(filelist[i], ".tif")) {
index = lastIndexOf(filelist[i], ".");
a = substring(filelist[i], index-1, index);
b = substring(filelist[i], index-2, index-1);
if(!isNaN(a) &&amp; isNaN(b)) {
old = substring(filelist[i], index-1);
new = replace(filelist[i], old, "0"+old);
flag = File.rename(dir+filelist[i], dir+new);
}
}
}

}
// end

Ved

PS: Text editor or the browser adds "amp;" in the second if statement, which you'll need to delete to run this macro.
Post by Rainer M. Engel
Post by Herbie
Post by Ved Sharma
Dear ImageJ users,
I'm trying import->Image sequence in a directory, which contains 44
01_s1_t1.tif, ..., 01_s1_t11.tif
01_s2_t1.tif, ..., 01_s2_t11.tif
02_s1_t1.tif, ..., 02_s1_t11.tif
02_s2_t1.tif, ..., 02_s2_t11.tif
To import all the files containing "s1", I enter "s1" in the field
"File name contains:" and check "Sort names numerically". But I find
that the files ending with "t10.tif" and "t11.tif" do not appear after
"t9.tif", rather they appear at the end of the stack. Is this a bug?
Is there a better way to import these files?
I'm running ImageJ 1.46b5 on a Windows 7 machine.
Ved
What about using t09.tiff instead of t9.tiff ?
If this poses problems, then you might use a utility for batch renaming
files before you open them in IJ. I don't know about such utilities for
Windows but they must exist and most probably some of them are free.
HTH
Herbie
------------------------
<http://www.gluender.de>
On Windows I would recommend these free tools..
http://www.bulkrenameutility.co.uk
or http://www.xnview.com/
Interesting read Norbert and I would second your suggestion.
regards,
Rainer
Rasband, Wayne (NIH/NIMH) [E]
2011-11-26 17:41:19 UTC
Permalink
Post by Ved Sharma
Dear ImageJ users,
01_s1_t1.tif, ..., 01_s1_t11.tif
01_s2_t1.tif, ..., 01_s2_t11.tif
02_s1_t1.tif, ..., 02_s1_t11.tif
02_s2_t1.tif, ..., 02_s2_t11.tif
To import all the files containing "s1", I enter "s1" in the field "File name contains:" and check "Sort names numerically". But I find that the files ending with "t10.tif" and "t11.tif" do not appear after "t9.tif", rather they appear at the end of the stack. Is this a bug? Is there a better way to import these files?
This bug is fixed in the ImageJ 1.46b daily build, thanks to a new sorting routine contributed by Norbert Vischer. Your sequence is now opened as:

01_s1_t1.tif
01_s1_t11.tif
01_s2_t1.tif
01_s2_t11.tif
02_s1_t1.tif
02_s1_t11.tif
02_s2_t1.tif
02_s2_t11.tif

Or as

01_s1_t1.tif
01_s1_t11.tif
02_s1_t1.tif
02_s1_t11.tif

if you enter "s1" in the "File name contains:" field.

-wayne

Loading...