Generalized dicom series reader

Hi,

I am trying to write a generalized reader code for dicom series.

To get the component type of the data i am reading first dicom file of the series and using dicomIO->GetComponentType() .This will give whether the data is of uchar/char/unsigned short/short etc.

typedef itk::GDCMImageIO       ImageIOType;
ImageIOType::Pointer dicomIO = ImageIOType::New();
dicomIO->LoadPrivateTagsOn();
using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO(dicomIO);
reader->SetFileName(msclr::interop::marshal_as<std::string>(filename));
try
{
	reader->Update();
}
catch (itk::ExceptionObject & excp)
{
	
}

int componentType = dicomIO->GetComponentType();

After that I am trying to create the series reader according to the component type.

using PixelType = signed short;
using ImageType = itk::Image<PixelType, 3>;

 typedef itk::GDCMImageIO       ImageIOType;
 ImageIOType::Pointer dicomIO = ImageIOType::New();

 typedef itk::GDCMSeriesFileNames NamesGeneratorType;
 NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
 nameGenerator->SetUseSeriesDetails(true);
 nameGenerator->AddSeriesRestriction("0008|0021");
 nameGenerator->SetDirectory(""D:\\TestDicoms");

 typedef std::vector< std::string >    SeriesIdContainer;
 const SeriesIdContainer& seriesUID = nameGenerator->GetSeriesUIDs();
 SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
 SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
 while (seriesItr != seriesEnd)
 {
	 ++seriesItr;
 }
 std::string seriesIdentifier;
 seriesIdentifier = seriesUID.begin()->c_str();
 typedef std::vector< std::string >   FileNamesContainer;
 FileNamesContainer fileNames;
 fileNames = nameGenerator->GetFileNames(seriesIdentifier);

 typedef itk::ImageSeriesReader< ImageType >       ReaderType;
 ReaderType::Pointer reader = ReaderType::New();
 reader->SetImageIO(dicomIO);
 reader->SetFileNames(fileNames);
 try
 {
	 reader->Update();
 }
 catch (itk::ExceptionObject xptn)
 {
	 
 }

How to set the PixelType according to component type.

Also is it the correct way to implement generalized reader?

Hi @Hasna,

This example shows how to support unknown image pixel types:

https://itk.org/ITKExamples/src/IO/ImageBase/ReadUnknownImageType/Documentation.html

Here is another DICOM example that may be useful:

https://itk.org/ITKExamples/src/IO/GDCM/ReadDICOMSeriesAndWrite3DImage/Documentation.html

Hope this helps,
Matt

Hi @matt.mccormick ,

Thank you for the suggestions. I will check them.

1 Like