Sorting Images in DO.NET

Sorting Images using DicomObjects.NET is slightly different from using the COM version, but the user has more flexibility as we provide an ArrayList wrapper to the DicomImageCollection object so that people can use all ArrayList's intrinsic methods to arrange the sorting.

However, you still need to write your own "Comparer" routine in order to use the "Sort" method of the ArrayList object, and by doing so you can have customized sorting facilities to suit your need.

Following is some C# code to get you started.

The Comparer Classes

To sort Images in DicomImageCollection, you can create your own ImageComparer class

public class ImageComparerClass : IComparer  
    int IComparer.Compare(object a, object b)  
         // Cast the objects to DicomImage
         DicomObjects.DicomImage ImageA = (DicomObjects.DicomImage) a;
         DicomObjects.DicomImage ImageB = (DicomObjects.DicomImage) b;

         // Sort AccessionNumber in ascending order		 
         string strA = ImageA.AccessionNumber;
         string strB = ImageB.AccessionNumber;         
         return( Decimal.Compare(Convert.ToDecimal(strA), Convert.ToDecimal(strB))); 

To sort DataSets in DicomDataSetCollection, create your own DataSetComparer class

public class DataSetComparerClass : IComparer  
    int IComparer.Compare(object a, object b)  
         // Cast the objects to DicomDataSet
         DicomObjects.DicomDataSet DataSetA = (DicomObjects.DicomDataSet) a;
         DicomObjects.DicomDataSet DataSetB = (DicomObjects.DicomDataSet) b;

         // Sort AccessionNumber in Descending order		 
         string strA = DataSetA[0x0008, 0x0050].Value; //this equals to DataSetA.AccessionNumber
         string strB = DataSetB[0x0008, 0x0050].Value; //this equals to DataSetB.AccessionNumber      
         return( Decimal.Compare(Convert.ToDecimal(strB), Convert.ToDecimal(strA))); 

Get it Sorted!

The following code shows how to sort the DicomImageCollection

ArrayList imageList = new ArrayList(Viewer.Images.ToList());	// an ArrayList wrapper
ImageComparerClass myImageComparer = new ImageComparerClass();

//sort the entire collection
imageList.Sort(0, Viewer.Images.Count, myImageComparer);

Please note, the newly created ArrayList does NOT copy the contents of the Images collection, it only creates an ArrayList wrapper around the DicomImage collection, which derived from IList. Therefore changes to the Images collection also affect the ArrayList and vice versa.

Follow the link for more information about Sorting_Images using COM version of DicomObejcts.


We Currently Accept:

Other currencies

For Reference purposes only:

The price is based on current exchange rates but is only an approximation. Please contact us for a final price