Sometimes (eg: with MR from HEH), the basic algorithm is not sufficient to sort dicom slices
It is the case when multiples sequences are in the same image, the z position is the same for a same slice in all sequences, it creates conflict
In such a case, we can sort slices according instanceNumber
std::map< std::string, std::vector<double> > theorigin;
std::map< std::string, std::vector<double> > theorientation;
std::map< std::string, std::vector<double> > sliceLocations;
std::map< std::string, std::vector<double> > theorigin;
std::map< std::string, std::vector<double> > theorientation;
std::map< std::string, std::vector<double> > sliceLocations;
+ std::map< std::string, std::vector<double> > instanceNumber;
std::map< std::string, std::vector<std::string> > seriesFiles;
#if GDCM_MAJOR_VERSION >= 2
if (args_info.verbose_flag)
std::map< std::string, std::vector<std::string> > seriesFiles;
#if GDCM_MAJOR_VERSION >= 2
if (args_info.verbose_flag)
sliceLocations[series_UID].push_back(theorigin[series_UID][2]);
seriesFiles[series_UID].push_back(input_files[i]);
sliceLocations[series_UID].push_back(theorigin[series_UID][2]);
seriesFiles[series_UID].push_back(input_files[i]);
+ gdcm::Attribute<0x20,0x0013> instanceNumber_att;
+ instanceNumber_att.SetFromDataSet(ds);
+ instanceNumber[series_UID].push_back(instanceNumber_att.GetValue());
+
gdcm::Attribute<0x28, 0x100> pixel_size;
pixel_size.SetFromDataSet(ds);
/* if (pixel_size.GetValue() != 16)
gdcm::Attribute<0x28, 0x100> pixel_size;
pixel_size.SetFromDataSet(ds);
/* if (pixel_size.GetValue() != 16)
while ( sn != series_UIDs.end() ) {
std::vector<double> locs = sliceLocations[*sn];
std::vector<double> origin = theorigin[*sn];
while ( sn != series_UIDs.end() ) {
std::vector<double> locs = sliceLocations[*sn];
std::vector<double> origin = theorigin[*sn];
+ std::vector<double> instanceNumberSerie = instanceNumber[*sn];
std::vector<std::string> files = seriesFiles[*sn];
std::vector<int> sliceIndex(files.size());
//clitk::GetSortedIndex(locs, sliceIndex);
std::vector<std::string> files = seriesFiles[*sn];
std::vector<int> sliceIndex(files.size());
//clitk::GetSortedIndex(locs, sliceIndex);
// Create ordered vector of filenames
std::vector<std::string> sorted_files;
sorted_files.resize(sliceIndex.size());
// Create ordered vector of filenames
std::vector<std::string> sorted_files;
sorted_files.resize(sliceIndex.size());
- for(unsigned int i=0; i<sliceIndex.size(); i++)
- sorted_files[i] = files[ sliceIndex[i] ];
+ if (!args_info.instanceNumber_flag) {
+ for(unsigned int i=0; i<sliceIndex.size(); i++)
+ sorted_files[i] = files[ sliceIndex[i] ];
+ } else {
+ std::vector<double>::iterator maxInstanceNumber = std::max_element(instanceNumberSerie.begin(), instanceNumberSerie.end());
+ std::vector<std::string> instanceNumberTemp(*maxInstanceNumber, "");
+ for(unsigned int i=0; i<instanceNumberSerie.size(); i++)
+ instanceNumberTemp[instanceNumberSerie[i]-1] = files[i];
+ unsigned int fillFiles(0);
+ for(unsigned int i=0; i<instanceNumberTemp.size(); i++) {
+ if (instanceNumberTemp[i] != "") {
+ sorted_files[fillFiles] = instanceNumberTemp[i];
+ ++fillFiles;
+ }
+ }
+ }
//===========================================
// Read write serie
//===========================================
// Read write serie
option "std_input" - "Take the like of input file from stdin, to support huge lists of filenames" flag off
option "focal_origin" - "Output files with FOCAL-like origin, instead of the origin present in the dicom files" flag off
option "patientSystem" p "Open the image with patient coordinate system" flag off
option "std_input" - "Take the like of input file from stdin, to support huge lists of filenames" flag off
option "focal_origin" - "Output files with FOCAL-like origin, instead of the origin present in the dicom files" flag off
option "patientSystem" p "Open the image with patient coordinate system" flag off
+option "instanceNumber" n "Sort the images regarding instance number in dicom tag" flag off