Login  Register

File import, sort names numerically not working.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

File import, sort names numerically not working.

ved sharma
56 posts
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
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: File import, sort names numerically not working.

Herbie-6
22 posts
>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

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>
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: File import, sort names numerically not working.

Norbert Vischer
10 posts
In reply to this post by ved sharma
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
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: File import, sort names numerically not working.

Rainer M. Engel
169 posts
In reply to this post by Herbie-6
Am 22.11.2011 18:59, schrieb Herbie:

>> 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
>
> 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
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: File import, sort names numerically not working.

ved sharma
56 posts
In reply to this post by ved sharma
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.

On Wed, 23 Nov 2011 10:57:24 +0100, Rainer M. Engel <[hidden email]> wrote:

>Am 22.11.2011 18:59, schrieb Herbie:
>>> 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
>>
>> 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
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: File import, sort names numerically not working.

Rasband, Wayne (NIH/NIMH) [E]
1064 posts
In reply to this post by ved sharma
On Nov 22, 2011, at 12:51 PM, Ved Sharma wrote:

> 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?

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