29 #include <itksys/SystemTools.hxx> 31 #include <itkImageFileReader.h> 32 #include <itkImageSeriesReader.h> 33 #include <itkImageFileWriter.h> 34 #include <itkTransformFileReader.h> 35 #include <itkTransform.h> 36 #include <itkTransformFactoryBase.h> 37 #include <itkGDCMImageIO.h> 38 #include <itkGDCMSeriesFileNames.h> 39 #include <itkOrientImageFilter.h> 40 #include <itkExtractImageFilter.h> 41 #if (ITK_VERSION_MAJOR > 3) 42 #include <itkComposeImageFilter.h> 47 #include <vtkSmartPointer.h> 48 #include <vtkCommand.h> 49 #include <vtkMatrix4x4.h> 50 #include <vtkImageData.h> 51 #include <vtkImageFlip.h> 52 #include <vtkPolyData.h> 53 #include <vtkPolyDataCollection.h> 54 #include <vtkTransformCollection.h> 56 #include <vtkCamera.h> 57 #include <vtkXMLImageDataReader.h> 58 #include <vtkXMLImageDataWriter.h> 61 #include "itkImageToVTKImageFilter.h" 62 #include "itkVTKImageToImageFilter.h" 66 #include <milxGlobal.h> 115 static bool CanReadImage(
const std::string filename);
130 static bool ReadImageInformation(
const std::string filename, std::string &pixeltype, std::string &componentType,
size_t &dimensions);
137 static std::vector<std::string> GetSupportedImageFileExtensions();
145 template<
class TImage>
146 static bool OpenImage(
const std::string filename,
typename itk::SmartPointer<TImage> &data);
147 #if (ITK_VERSION_MAJOR > 3) 166 template<
class TImage,
size_t TDim>
167 static bool OpenAsVectorImage(
const std::string filename,
typename itk::SmartPointer< itk::VectorImage< typename TImage::InternalPixelType, TDim> > &data);
176 template<
class TImage>
177 static bool OpenImages(std::vector<std::string> &filenames, std::vector<
typename itk::SmartPointer<TImage> > &images);
185 template<
class TImage>
186 static bool SaveImage(
const std::string filename,
typename itk::SmartPointer<TImage> data, itk::ImageIOBase *io = NULL);
194 template<
class TImage>
195 static bool SaveImages(std::vector<std::string> &filenames,
const std::vector<
typename itk::SmartPointer<TImage> > images);
206 static std::vector<std::string> GetDICOMSeriesUIDs(
const std::string directoryPath,
bool recursive =
false);
215 static std::vector<std::string> GetDICOMSeriesFilenames(
const std::string directoryPath,
const std::string seriesName,
bool recursive =
false);
224 template<
class TImage>
225 static bool GetDICOMData(
const std::string directoryPath,
typename itk::SmartPointer<TImage> &data, itk::MetaDataDictionary &dict, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive =
false);
232 template<
class TImage>
233 static bool GetDICOMMetaData(
const std::string directoryPath, itk::MetaDataDictionary &dict, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive =
false);
240 template<
class TImage>
241 static bool GetDICOMTags(
const std::string directoryPath, std::vector< std::pair<std::string, std::string> > &tags, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive =
false);
242 template<
class TImage>
243 static bool GetDICOMTags(
const itk::MetaDataDictionary dictionary, std::vector< std::pair<std::string, std::string> > &tags);
253 template<
class TImage>
254 static bool OpenDICOMSeries(
const std::string directoryPath,
typename itk::SmartPointer<TImage> &data, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive =
false);
255 template<
class TImage>
256 static bool OpenDICOMSeriesAndTags(
const std::string directoryPath,
typename itk::SmartPointer<TImage> &data, std::vector< std::pair<std::string, std::string> > &tags, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive =
false);
268 template<
class TImage>
269 static bool OpenImage(
const std::string filename, vtkSmartPointer<vtkImageData> &data);
277 template<
class TImage>
278 static bool SaveImage(
const std::string filename, vtkSmartPointer<vtkImageData> &data);
288 template<
class TImage>
289 inline static itk::SmartPointer<TImage> ReadImageUsingITK(
const std::string filename);
295 template<
class TImage>
296 inline static bool WriteImageUsingITK(
const std::string filename, itk::SmartPointer<TImage> data);
306 template<
class TType>
307 static itk::SmartPointer< itk::Transform<TType> > OpenTransform(std::string filename);
316 static vtkMatrix4x4* OpenITKTransform(std::string filename);
323 static vtkMatrix4x4* OpenVTKTransform(std::string filename);
330 static void SaveITKTransform(std::string filename,
const vtkMatrix4x4 * matrix);
346 static void SaveVTKTransform(std::string filename,
const vtkMatrix4x4 * matrix);
359 static bool OpenModel(
const std::string filename, vtkSmartPointer<vtkPolyData> &data);
366 static bool OpenModelCollection(std::vector<std::string> filenames, vtkSmartPointer<vtkPolyDataCollection> &collection);
373 static bool SaveModel(
const std::string filename, vtkSmartPointer<vtkPolyData> data,
const bool binary =
false);
380 static bool SaveModelCollection(std::vector<std::string> filenames, vtkSmartPointer<vtkPolyDataCollection> collection,
const bool binary =
false);
387 static bool SaveTransform(
const std::string filename, vtkSmartPointer<vtkTransform> data,
const bool ITK =
false);
394 static bool SaveTransformCollection(std::vector<std::string> filenames, vtkSmartPointer<vtkTransformCollection> collection,
const bool ITK =
false);
403 static bool OpenDelimitedText(
const std::string filename, vtkSmartPointer<vtkTable> &data,
const std::string delimiter =
",");
410 static bool SaveDelimitedText(
const std::string filename,
const vtkSmartPointer<vtkTable> data,
const std::string delimiter =
",");
413 static bool SaveCamera(
const std::string filename,
const vtkSmartPointer<vtkCamera> camera);
414 static bool LoadCamera(
const std::string filename, vtkSmartPointer<vtkCamera> &camera);
423 std::transform(filename.begin(), filename.end(), filename.begin(), ::tolower);
432 static inline std::string StripFileExtension(
const std::string &filename)
434 return filename.substr(0, filename.find_last_of(
"."));
442 static inline std::string
ExtractFilename(
const std::string &filename,
char delimiter =
'/')
444 return filename.substr( filename.find_last_of( delimiter ) + 1 );
452 static inline std::string
ExtractPath(
const std::string &filename,
char delimiter =
'/')
454 return filename.substr( 0, filename.find_last_of( delimiter ) + 1 );
462 static inline std::string GetBaseName(
const std::string &filename)
464 return StripFileExtension( ExtractFilename(filename) );
474 if (filename.find_last_of(
".") != std::string::npos)
475 return StringToLowerCase( filename.substr(filename.find_last_of(
".")+1) );
482 static bool Exists(
const std::string filename)
485 if (stat(filename.c_str(), &buffer) != -1)
497 itksys::SystemTools::MakeDirectory( itksys::SystemTools::GetRealPath(name) );
508 template<
class TImage>
509 bool File::OpenImage(
const std::string filename,
typename itk::SmartPointer<TImage> &data)
511 if(!Exists(filename))
513 std::cerr <<
"File " << filename <<
" doesn't exist. Ignoring." << std::endl;
517 data = ReadImageUsingITK<TImage>(filename);
525 #if (ITK_VERSION_MAJOR > 3) 526 template<
class TImage,
size_t TDim>
528 bool File::OpenAsVectorImage(
const std::string filename,
typename itk::SmartPointer< itk::VectorImage< typename TImage::InternalPixelType, TDim> > &data)
530 if(!Exists(filename))
532 std::cerr <<
"File " << filename <<
" doesn't exist. Ignoring." << std::endl;
537 typename TImage::Pointer image = ReadImageUsingITK<TImage>(filename);
542 typedef itk::Image< typename TImage::InternalPixelType, TDim > TImageSlice;
543 typedef itk::ComposeImageFilter<TImageSlice> ImageToVectorImageFilterType;
544 typename ImageToVectorImageFilterType::Pointer imageToVectorImageFilter = ImageToVectorImageFilterType::New();
545 typename TImage::SizeType size = image->GetLargestPossibleRegion().GetSize();
546 std::cout <<
"Image Size: " << size[0] <<
"x" << size[1] <<
"x" << size[2] <<
"x" << size[3] << std::endl;
547 for(
size_t j = 0; j < size[3]; j ++)
549 typename TImage::IndexType desiredStart;
550 desiredStart.Fill(0);
553 typename TImage::SizeType desiredSize;
554 desiredSize[0] = size[0];
555 desiredSize[1] = size[1];
556 desiredSize[2] = size[2];
559 typename TImage::RegionType desiredRegion(desiredStart, desiredSize);
562 typedef itk::ExtractImageFilter<TImage, TImageSlice> FilterType;
563 typename FilterType::Pointer filter = FilterType::New();
564 filter->SetExtractionRegion(desiredRegion);
565 filter->SetInput(image);
566 #if ITK_VERSION_MAJOR >= 4 567 filter->SetDirectionCollapseToIdentity();
572 imageToVectorImageFilter->SetInput(j, filter->GetOutput());
574 imageToVectorImageFilter->Update();
576 data = imageToVectorImageFilter->GetOutput();
585 template<
class TImage>
586 bool File::OpenImages(std::vector<std::string> &filenames, std::vector<
typename itk::SmartPointer<TImage> > &images)
588 if(filenames.empty())
591 std::vector<std::string> readFilenames;
592 for(
size_t j = 0; j < filenames.size(); j ++)
594 typename itk::SmartPointer<TImage> image;
595 bool success = OpenImage(filenames[j], image);
598 readFilenames.push_back(filenames[j]);
599 images.push_back(image);
605 filenames = readFilenames;
610 template<
class TImage>
611 bool File::SaveImage(
const std::string filename,
typename itk::SmartPointer<TImage> data, itk::ImageIOBase *io)
613 typedef itk::ImageFileWriter<TImage> ImageWriter;
615 typename ImageWriter::Pointer writer = ImageWriter::New();
616 writer->UseInputMetaDataDictionaryOn();
617 writer->SetInput(data);
618 writer->SetFileName(filename.c_str());
620 writer->SetImageIO(io);
621 writer->AddObserver(itk::ProgressEvent(), ProgressUpdates);
626 catch( itk::ExceptionObject & err )
628 std::cerr <<
"File Exception caught while writing!" << std::endl;
629 std::cerr << err << std::endl;
636 template<
class TImage>
637 bool File::SaveImages(std::vector<std::string> &filenames,
const std::vector<
typename itk::SmartPointer<TImage> > images)
639 if(filenames.empty())
642 std::vector<std::string> readFilenames;
643 for(
size_t j = 0; j < filenames.size(); j ++)
645 bool success = SaveImage<TImage>(filenames[j], images[j]);
646 if(success && images[j])
647 readFilenames.push_back(filenames[j]);
652 filenames = readFilenames;
658 template<
class TImage>
659 bool File::GetDICOMData(
const std::string directoryPath,
typename itk::SmartPointer<TImage> &data, itk::MetaDataDictionary &dict, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive)
661 typedef itk::ImageSeriesReader<TImage> ReaderType;
662 typedef itk::GDCMImageIO ImageIOType;
664 const std::vector<std::string> filenames = GetDICOMSeriesFilenames(directoryPath, seriesName, recursive);
666 ImageIOType::Pointer gdcmIO = ImageIOType::New();
667 typename ReaderType::Pointer reader = ReaderType::New();
668 reader->SetImageIO(gdcmIO);
669 reader->SetFileNames(filenames);
670 reader->AddObserver(itk::ProgressEvent(), ProgressUpdates);
675 catch (itk::ExceptionObject &excp)
677 std::cerr <<
"File Exception caught while reading series!" << std::endl;
678 std::cerr << excp << std::endl;
683 typedef itk::MetaDataObject< std::string > MetaDataStringType;
684 std::string series_type_id(
"0008|103e");
685 itk::MetaDataDictionary & dic = gdcmIO->GetMetaDataDictionary();
686 itk::MetaDataDictionary::ConstIterator series_type_itr = dic.Find(series_type_id);
687 std::string caseId =
"0010|0020";
688 itk::MetaDataDictionary::ConstIterator case_itr = dic.Find(caseId);
689 std::string echoNumber =
"0018|0086";
690 itk::MetaDataDictionary::ConstIterator echoNumber_itr = dic.Find(echoNumber);
691 std::string seriesNumber =
"0020|0011";
692 itk::MetaDataDictionary::ConstIterator seriesNumber_itr = dic.Find(seriesNumber);
693 std::string acqNumber =
"0020|0012";
694 itk::MetaDataDictionary::ConstIterator acqNumber_itr = dic.Find(acqNumber);
695 std::string instanceNumber =
"0020|0013";
696 itk::MetaDataDictionary::ConstIterator instanceNumber_itr = dic.Find(instanceNumber);
697 std::string itemNumber =
"0020|0019";
698 itk::MetaDataDictionary::ConstIterator itemNumber_itr = dic.Find(itemNumber);
700 MetaDataStringType::ConstPointer entryValue =
dynamic_cast<const MetaDataStringType *
>(series_type_itr->second.GetPointer());
703 seriesName = entryValue->GetMetaDataObjectValue();
704 std::cout <<
"Series: " << entryValue->GetMetaDataObjectValue() << std::endl;
706 MetaDataStringType::ConstPointer entryValue2 =
dynamic_cast<const MetaDataStringType *
>(case_itr->second.GetPointer());
709 caseID = entryValue2->GetMetaDataObjectValue();
710 std::cout <<
"Case: " << entryValue2->GetMetaDataObjectValue() << std::endl;
712 MetaDataStringType::ConstPointer entryValue3;
713 if (dic.HasKey(echoNumber))
715 entryValue3 =
dynamic_cast<const MetaDataStringType *
>(echoNumber_itr->second.GetPointer());
716 echoID = entryValue3->GetMetaDataObjectValue();
717 std::cout <<
"Echo Number: " << entryValue3->GetMetaDataObjectValue() << std::endl;
719 MetaDataStringType::ConstPointer entryValue4;
720 if (dic.HasKey(seriesNumber))
722 entryValue4 =
dynamic_cast<const MetaDataStringType *
>(seriesNumber_itr->second.GetPointer());
723 seriesID = entryValue4->GetMetaDataObjectValue();
724 std::cout <<
"Series Number: " << entryValue4->GetMetaDataObjectValue() << std::endl;
726 MetaDataStringType::ConstPointer entryValue5;
727 if (dic.HasKey(acqNumber))
729 entryValue5 =
dynamic_cast<const MetaDataStringType *
>(acqNumber_itr->second.GetPointer());
730 acqID = entryValue5->GetMetaDataObjectValue();
731 std::cout <<
"Acquisition Number: " << entryValue5->GetMetaDataObjectValue() << std::endl;
733 MetaDataStringType::ConstPointer entryValue6;
734 if (dic.HasKey(instanceNumber))
736 entryValue6 =
dynamic_cast<const MetaDataStringType *
>(instanceNumber_itr->second.GetPointer());
737 instanceID = entryValue6->GetMetaDataObjectValue();
738 std::cout <<
"Instance Number: " << entryValue6->GetMetaDataObjectValue() << std::endl;
740 MetaDataStringType::ConstPointer entryValue7;
741 if (dic.HasKey(itemNumber))
743 entryValue7 =
dynamic_cast<const MetaDataStringType *
>(itemNumber_itr->second.GetPointer());
744 std::cout <<
"Item Number: " << entryValue7->GetMetaDataObjectValue() << std::endl;
748 dict = gdcmIO->GetMetaDataDictionary();
750 data = reader->GetOutput();
755 template<
class TImage>
756 bool File::GetDICOMMetaData(
const std::string directoryPath, itk::MetaDataDictionary &dict, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive)
758 typename itk::SmartPointer<TImage> data;
760 if (!GetDICOMData<TImage>(directoryPath, data, dict, seriesName, caseID, echoID, seriesID, acqID, instanceID, recursive))
766 template<
class TImage>
767 bool File::GetDICOMTags(
const std::string directoryPath, std::vector< std::pair<std::string, std::string> > &tags, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive)
769 typedef itk::MetaDataObject< std::string > MetaDataStringType;
770 typedef itk::MetaDataDictionary DictionaryType;
771 DictionaryType dictionary;
772 if (!GetDICOMMetaData<TImage>(directoryPath, dictionary, seriesName, caseID, echoID, seriesID, acqID, instanceID, recursive))
775 DictionaryType::ConstIterator itr = dictionary.Begin();
776 DictionaryType::ConstIterator end = dictionary.End();
780 itk::MetaDataObjectBase::Pointer entry = itr->second;
781 MetaDataStringType::Pointer entryvalue =
dynamic_cast<MetaDataStringType *
>(entry.GetPointer());
782 std::string entryTag = itr->first;
785 std::pair<std::string, std::string> entryPair = std::make_pair(entryTag, entryvalue->GetMetaDataObjectValue());
786 tags.push_back(entryPair);
794 template<
class TImage>
795 bool File::GetDICOMTags(
const itk::MetaDataDictionary dictionary, std::vector< std::pair<std::string, std::string> > &tags)
797 typedef itk::MetaDataObject< std::string > MetaDataStringType;
798 typedef itk::MetaDataDictionary DictionaryType;
800 DictionaryType::ConstIterator itr = dictionary.Begin();
801 DictionaryType::ConstIterator end = dictionary.End();
805 itk::MetaDataObjectBase::Pointer entry = itr->second;
806 MetaDataStringType::Pointer entryvalue =
dynamic_cast<MetaDataStringType *
>(entry.GetPointer());
807 std::string entryTag = itr->first;
810 std::pair<std::string, std::string> entryPair = std::make_pair(entryTag, entryvalue->GetMetaDataObjectValue());
811 tags.push_back(entryPair);
819 template<
class TImage>
820 bool File::OpenDICOMSeries(
const std::string directoryPath,
typename itk::SmartPointer<TImage> &data, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive)
822 typedef itk::MetaDataDictionary DictionaryType;
823 DictionaryType dictionary;
825 if (!GetDICOMData<TImage>(directoryPath, data, dictionary, seriesName, caseID, echoID, seriesID, acqID, instanceID, recursive))
831 template<
class TImage>
832 bool File::OpenDICOMSeriesAndTags(
const std::string directoryPath,
typename itk::SmartPointer<TImage> &data, std::vector< std::pair<std::string, std::string> > &tags, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID,
bool recursive)
834 typedef itk::MetaDataDictionary DictionaryType;
835 DictionaryType dictionary;
837 if (!GetDICOMData<TImage>(directoryPath, data, dictionary, seriesName, caseID, echoID, seriesID, acqID, instanceID, recursive))
840 if (!milx::File::GetDICOMTags<TImage>(dictionary, tags))
849 template<
class TImage>
852 std::string extension = GetFileExtension(filename);
853 vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
855 if(!Exists(filename))
858 if(extension ==
"vti")
860 vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
862 if(reader->CanReadFile(filename.c_str()))
864 reader->SetFileName(filename.c_str());
865 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
869 if(!errorObserver->ReportsFailure())
871 data = reader->GetOutput();
875 std::cerr <<
"VTK XML Image Reader Encountered the following error." << std::endl;
876 std::cerr << errorObserver->GetMessage() << std::endl;
882 std::cerr <<
"Could not locate VTK XML Image (VTI) file!" << std::endl;
888 typename itk::SmartPointer<TImage> tmpImage;
890 if( !OpenImage(filename, tmpImage) )
893 typedef itk::ImageToVTKImageFilter<TImage> ConnectorType;
895 typename ConnectorType::Pointer connector = ConnectorType::New();
896 connector->SetInput(tmpImage);
900 vtkSmartPointer<vtkImageFlip> imageReorient = vtkSmartPointer<vtkImageFlip>::New();
901 #if VTK_MAJOR_VERSION <= 5 902 imageReorient->SetInput(connector->GetOutput());
904 imageReorient->SetInputData(connector->GetOutput());
906 imageReorient->SetFilteredAxis(1);
907 imageReorient->FlipAboutOriginOn();
908 imageReorient->AddObserver(vtkCommand::ErrorEvent, errorObserver);
909 imageReorient->Update();
911 if(errorObserver->ReportsFailure())
913 std::cerr <<
"Reader Encountered the following error." << endl;
914 std::cerr << errorObserver->GetMessage() << endl;
918 data = imageReorient->GetOutput();
924 template<
class TImage>
927 std::string extension = GetFileExtension(filename);
930 vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
931 vtkSmartPointer<vtkImageFlip> imageReorient = vtkSmartPointer<vtkImageFlip>::New();
932 #if VTK_MAJOR_VERSION <= 5 933 imageReorient->SetInput(data);
935 imageReorient->SetInputData(data);
937 imageReorient->SetFilteredAxis(1);
938 imageReorient->FlipAboutOriginOn();
939 imageReorient->AddObserver(vtkCommand::ErrorEvent, errorObserver);
940 imageReorient->Update();
942 if(errorObserver->ReportsFailure())
944 std::cerr <<
"Writer Encountered the following error." << std::endl;
945 std::cerr << errorObserver->GetMessage() << std::endl;
949 if(extension ==
"vti")
951 vtkSmartPointer<vtkXMLImageDataWriter> writer = vtkSmartPointer<vtkXMLImageDataWriter>::New();
952 #if VTK_MAJOR_VERSION <= 5 953 writer->SetInput(data);
955 writer->SetInputData(data);
957 writer->SetFileName(filename.c_str());
958 writer->SetDataModeToBinary();
959 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
963 if(errorObserver->ReportsFailure())
965 std::cerr <<
"VTK XML Image Writer Encountered the following error." << std::endl;
966 std::cerr << errorObserver->GetMessage() << std::endl;
971 typedef itk::VTKImageToImageFilter<TImage> ConnectorType;
973 typename ConnectorType::Pointer connector = ConnectorType::New();
974 connector->SetInput(imageReorient->GetOutput());
977 if( !SaveImage<TImage>(filename, connector->GetOutput()) )
987 template<
class TImage>
990 typedef itk::ImageFileReader<TImage, itk::DefaultConvertPixelTraits<typename TImage::InternalPixelType> > ImageReader;
991 typename ImageReader::Pointer reader = ImageReader::New();
992 reader->SetFileName(filename.c_str());
993 reader->AddObserver(itk::ProgressEvent(), milx::ProgressUpdates);
998 catch( itk::ExceptionObject & err )
1000 std::cerr <<
"Reader Encountered the following error." << std::endl;
1001 std::cerr << err << std::endl;
1005 return reader->GetOutput();
1008 template<
class TImage>
1011 typedef itk::ImageFileWriter<TImage> ImageWriter;
1012 typename ImageWriter::Pointer writer = ImageWriter::New();
1013 writer->SetFileName(filename.c_str());
1014 writer->SetInput(data);
1015 writer->AddObserver(itk::ProgressEvent(), milx::ProgressUpdates);
1020 catch( itk::ExceptionObject & err )
1022 std::cerr <<
"Writer Encountered the following error." << std::endl;
1023 std::cerr << err << std::endl;
1030 template<
class TType>
1033 typedef itk::TransformFileReader TransformReaderType;
1034 typedef TransformReaderType::TransformListType * TransformListType;
1037 itk::TransformFactoryBase::RegisterDefaultTransforms();
1039 TransformReaderType::Pointer affineReader = TransformReaderType::New();
1040 affineReader->SetFileName(filename);
1041 affineReader->AddObserver(itk::ProgressEvent(), milx::ProgressUpdates);
1044 affineReader->Update();
1046 catch(itk::ExceptionObject &ex)
1048 PrintError(
"milxFile: Failed reading Transform " + std::string(ex.GetDescription()));
1052 return static_cast< itk::Transform<TType> *
>( (*(affineReader->GetTransformList()->begin())).GetPointer() );
1058 #endif //__MILXFILE_H static bool GetDICOMMetaData(const std::string directoryPath, itk::MetaDataDictionary &dict, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID, bool recursive=false)
Opens a DICOM series and returns the image meta data read by ITK/GDCM, i.e. the DICOM tags from the h...
static bool OpenDICOMSeries(const std::string directoryPath, typename itk::SmartPointer< TImage > &data, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID, bool recursive=false)
Opens a DICOM series from the path given. Returns the image volume from the series read by ITK/GDCM...
static std::string ExtractFilename(const std::string &filename, char delimiter='/')
Returns filename (with extension) with paths removed.
static itk::SmartPointer< TImage > ReadImageUsingITK(const std::string filename)
Opens the image using the ITK file reader class. Returns NULL if failed and outputs the error to std ...
static std::string ExtractPath(const std::string &filename, char delimiter='/')
Returns the path of the filename with the basename removed.
void PrintError(const std::string msg)
Displays a generic msg to standard error with carriage return.
static bool Exists(const std::string filename)
Returns true if the file already exists.
static bool GetDICOMTags(const std::string directoryPath, std::vector< std::pair< std::string, std::string > > &tags, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID, bool recursive=false)
Opens a DICOM series and returns the DICOM tags read by ITK/GDCM, i.e. the DICOM tags from the header...
#define SMILI_EXPORT
DLL Function Symbol for Windows. It is empty for other OSes.
static bool GetDICOMData(const std::string directoryPath, typename itk::SmartPointer< TImage > &data, itk::MetaDataDictionary &dict, std::string &seriesName, std::string &caseID, std::string &echoID, std::string &seriesID, std::string &acqID, std::string &instanceID, bool recursive=false)
Opens a DICOM series and returns the image meta data read by ITK/GDCM, i.e. the DICOM tags from the h...
static bool OpenImage(const std::string filename, typename itk::SmartPointer< TImage > &data)
Opens an image file, which is any of the following: JPEG, PNG, DICOM, TIFF, NIFTI etc...
static bool SaveImage(const std::string filename, typename itk::SmartPointer< TImage > data, itk::ImageIOBase *io=NULL)
Saves an image file, which is any of the following: JPEG, PNG, DICOM, TIFF, NIFTI etc...
static bool OpenImages(std::vector< std::string > &filenames, std::vector< typename itk::SmartPointer< TImage > > &images)
Opens a number of images, which are any of the following: JPEG, PNG, DICOM, TIFF, NIFTI etc...
File()
Standard constructor.
static bool WriteImageUsingITK(const std::string filename, itk::SmartPointer< TImage > data)
Saves the image using the ITK file writer class. Returns NULL if failed and outputs the error to std ...
static void MakeDirectory(std::string name)
Creates directory (using ITK) if none exists.
virtual ~File()
Standard Destructor.
static std::string StringToLowerCase(std::string filename)
Returns a lower case version of the string.
static itk::SmartPointer< itk::Transform< TType > > OpenTransform(std::string filename)
Opens an ITK transform file and returns.
A general file IO class for reading writing images and models.
static std::string GetFileExtension(const std::string &filename)
Returns the file extension (in lower case) of the given filename.
static bool SaveImages(std::vector< std::string > &filenames, const std::vector< typename itk::SmartPointer< TImage > > images)
Saves a number of images, which are any of the following: JPEG, PNG, DICOM, TIFF, NIFTI etc...