View Issue Details

IDProjectCategoryView StatusLast Update
0003487Slicer4Module MultiVolume Exporter/Importerpublic2015-11-30 17:49
Reporterliuy5 Assigned Tofedorov  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product VersionSlicer 4.3.0 
Target VersionSlicer 4.4.0Fixed in VersionSlicer 4.4.0 
Summary0003487: incorret file name sorting in multivolume importer
Description

Have files like this:

1.dcm
2.dcm
...
10.dcm
...
20.dcm
...

However multivolume importer sort files like this:

1.dcm
10.dcm
...
2.dcm
20.dcm
...

These files are images at different time points so multivoulme importer messed up the whole dataset by changing order of time points.

TagsNo tags attached.

Activities

fedorov

fedorov

2013-11-08 06:26

developer   ~0010297

This is expected behavior, files are sorted by the importer in alphanumeric order. Please check the wiki documentation.

liuy5

liuy5

2014-01-07 09:23

developer   ~0010485

No this should not be expected behaviour. Even file explorer in Linux can sort these files correctly: 1, 2, 3, ...10, 20,... instead of 1, 10, 2, 20, 3, 30...

Which library are you using in importer? Is there an option to do correct file name sorting?

Thanks,

fedorov

fedorov

2014-01-07 13:26

developer   ~0010488

It is using sort() function of python.

In [5]: l=['1','2','11','12']
In [6]: l.sort()
In [7]: print l
['1', '11', '12', '2']

Why can't you just rename your files to be numbered 01, 02, 03, ..., 10, 11 ?

In [8]: l=['02','01','22','11']
In [9]: l.sort()
In [10]: print l
['01', '02', '11', '22']

2014-01-17 16:16

 

sort.py (685 bytes)
liuy5

liuy5

2014-01-17 16:17

developer   ~0010526

The files are dumped using another software and it would too much work to manually change file names every time.

I did a little bit search and turns out there are python ways to do "human sort". I have created a small python file to demonstrate the usage. The core part is simply 3 lines of code:

def human_sort(l):
""" Sort the given list in the way that humans expect.
"""
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
l.sort( key=alphanum_key )

Would you please to include this in your code to replace the default python sorting? It might be just 10 minutes work for you but it would save us lots of trouble. Plus it will make Slicer a lot user friendly.

You may see the sort function in the attached python file.

Many thanks!

fedorov

fedorov

2014-01-18 08:25

developer   ~0010527

I committed your fix in r22835. Thank you for oyur contribution!

jcfr

jcfr

2014-04-07 14:53

administrator   ~0011550

Closing resolved issues that have not been updated in more than 3 months

Issue History

Date Modified Username Field Change
2013-11-08 04:03 liuy5 New Issue
2013-11-08 04:03 liuy5 Status new => assigned
2013-11-08 04:03 liuy5 Assigned To => jcfr
2013-11-08 06:03 jcfr Assigned To jcfr => fedorov
2013-11-08 06:03 jcfr Category Core: Base Code => Module MultiVolumeImporter
2013-11-08 06:04 jcfr Target Version => Slicer 4.4.0
2013-11-08 06:26 fedorov Note Added: 0010297
2013-11-08 07:03 fedorov Status assigned => feedback
2014-01-07 09:23 liuy5 Note Added: 0010485
2014-01-07 13:26 fedorov Note Added: 0010488
2014-01-17 16:16 liuy5 File Added: sort.py
2014-01-17 16:17 liuy5 Note Added: 0010526
2014-01-18 08:25 fedorov Note Added: 0010527
2014-01-18 08:25 fedorov Status feedback => resolved
2014-01-18 08:25 fedorov Resolution open => fixed
2014-04-07 14:53 jcfr Note Added: 0011550
2014-04-07 14:53 jcfr Status resolved => closed
2014-04-07 14:53 jcfr Fixed in Version => Slicer 4.4.0
2015-11-30 17:49 jcfr Category Module MultiVolumeImporter => Module: MultiVolume Exporter/Importer