5 #ifndef TOMATO_TOMATO_EXPORTT1_MAGSIGNRECOV_H 6 #define TOMATO_TOMATO_EXPORTT1_MAGSIGNRECOV_H 8 #include "CmakeConfigForTomato.h" 11 #include "gdcmUIDGenerator.h" 12 #include "itkGDCMImageIO.h" 13 #include "itkGDCMSeriesFileNames.h" 14 #include "itkMultiplyImageFilter.h" 15 #include "itkImageFileWriter.h" 16 #include "itkFileTools.h" 17 #include "itkExtractImageFilter.h" 22 template<
typename MeasureType >
25 ::exportT1MagSignRecovToDicom(){
27 if (_opts->dir_output_magSignRecov.empty()) {
28 printf(
"No DICOM export, dir_output_magSignRecov not given.\n");
32 typedef itk::AdaptImageFilter < ImageType2D, OutputImageType, CastPixelAccessor< InputPixelType, OutputPixelType > > ImageAdaptorType;
33 typedef itk::ImageFileWriter<OutputImageType> WriterType;
34 typedef itk::ExtractImageFilter<ImageType3D, ImageType2D> ExtractImageFilterType;
37 itk::EncapsulateMetaData<std::string>( _dictionaryInput, std::string(
"0028|1052"),
"0");
38 itk::EncapsulateMetaData<std::string>( _dictionaryInput, std::string(
"0028|1053"),
"1");
41 DictionaryType dictionaryOutput_MagSignRecov(_dictionaryInput);
44 gdcm::UIDGenerator sopuid;
45 gdcm::UIDGenerator suid;
47 std::string seriesUID_MagSignRecov = suid.Generate();
50 std::string seriesNumber;
51 itk::ExposeMetaData<std::string>(_dictionaryInput,
"0020|0011", seriesNumber);
52 if (_opts->output_map_series_number == 0) {
53 _opts->output_map_series_number = KWUtil::StringToNumber<int>(seriesNumber) + 10004;
55 std::string newSeriesNumber_T1 = KWUtil::NumberToString(_opts->output_map_series_number);
58 typedef itk::GDCMImageIO ImageIOType;
59 ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
60 gdcmImageIO->KeepOriginalUIDOn();
63 typename ExtractImageFilterType::Pointer extractor = ExtractImageFilterType::New();
64 extractor->SetInput(_imageCalculatorItk->GetMagSignRecovered());
65 extractor->SetDirectionCollapseToIdentity();
66 typename ImageType3D::SizeType size = _imageCalculatorItk->GetMagSignRecovered()->GetLargestPossibleRegion().GetSize();
68 typename ImageType3D::IndexType extractorIndex;
69 extractorIndex.Fill(0);
70 typename ImageType3D::RegionType desiredRegion;
71 desiredRegion.SetSize(size);
72 desiredRegion.SetIndex(extractorIndex);
73 extractor->SetExtractionRegion(desiredRegion);
76 typename ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
79 typename WriterType::Pointer writer = WriterType::New();
80 writer->SetUseInputMetaDataDictionary(
false);
82 printf(
"Saving to: %s ", _opts->dir_output_magSignRecov.c_str());
84 for (
size_t iImage = 0; iImage < _opts->files_magnitude.size(); iImage++) {
86 MeasureType invTime = this->_invTimes[iImage];
88 std::string sopInstanceUID_MagSignRecov = sopuid.Generate();
90 itk::EncapsulateMetaData<std::string>(dictionaryOutput_MagSignRecov, std::string(
"0008|0018"), sopInstanceUID_MagSignRecov);
91 itk::EncapsulateMetaData<std::string>(dictionaryOutput_MagSignRecov, std::string(
"0002|0003"), sopInstanceUID_MagSignRecov);
92 itk::EncapsulateMetaData<std::string>(dictionaryOutput_MagSignRecov, std::string(
"0020|000e"), seriesUID_MagSignRecov);
93 itk::EncapsulateMetaData<std::string>(dictionaryOutput_MagSignRecov, std::string(
"0020|0011"), newSeriesNumber_T1);
94 itk::EncapsulateMetaData<std::string>(dictionaryOutput_MagSignRecov, std::string(
"0020|0013"), KWUtil::NumberToString(iImage));
95 itk::EncapsulateMetaData<std::string>(dictionaryOutput_MagSignRecov, std::string(
"0020|4000"),
"Tomato magnitude image with sign");
96 itk::EncapsulateMetaData<std::string>(dictionaryOutput_MagSignRecov, std::string(
"0018|0082"), KWUtil::NumberToString(invTime));
98 itk::FileTools::CreateDirectory(_opts->dir_output_magSignRecov);
101 gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_MagSignRecov);
104 extractorIndex[2] = iImage;
105 desiredRegion.SetIndex(extractorIndex);
106 extractor->SetExtractionRegion(desiredRegion);
109 adaptor->SetInput(extractor->GetOutput());
110 writer->SetFileName(_opts->dir_output_magSignRecov + KWUtil::PathSeparator() + KWUtil::NumberToString(iImage) +
".dcm");
111 writer->SetInput(adaptor->GetOutput());
112 writer->SetImageIO(gdcmImageIO);
115 }
catch (itk::ExceptionObject &e) {
116 std::cerr <<
"Exception in file writer " << std::endl;
117 std::cerr << e << std::endl;
121 std::cout <<
" Saved!" << std::endl;
130 #endif //TOMATO_TOMATO_EXPORTT1_MAGSIGNRECOV_H Definition: OxCalculator.h:19