From: tbaudier Date: Fri, 26 Jan 2018 08:24:46 +0000 (+0100) Subject: Be sure to have the correct origin in clitkImage2DicomDose output X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=b35856bdd1f55ef597d2a761597f58504b076c6b;p=clitk.git Be sure to have the correct origin in clitkImage2DicomDose output --- diff --git a/tools/clitkImage2DicomDoseGenericFilter.txx b/tools/clitkImage2DicomDoseGenericFilter.txx index 667340a..a349c74 100644 --- a/tools/clitkImage2DicomDoseGenericFilter.txx +++ b/tools/clitkImage2DicomDoseGenericFilter.txx @@ -151,9 +151,36 @@ Image2DicomDoseGenericFilter::UpdateWithDimAndPixelType() reader->SetFileName( filename ); reader->Update(); typename InputImageType::Pointer image = reader->GetOutput(); + std::ostringstream value; + + // Read Dicom model file + typename ReaderSeriesType::Pointer readerSeries = ReaderSeriesType::New(); + ImageIOType::Pointer gdcmIO = ImageIOType::New(); + std::string filename_out = m_ArgsInfo.output_arg; + gdcmIO->LoadPrivateTagsOn(); + gdcmIO->KeepOriginalUIDOn(); + typename ReaderSeriesType::FileNamesContainer fileNames; + fileNames.push_back(m_ArgsInfo.DicomInputFile_arg); + readerSeries->SetImageIO( gdcmIO ); + readerSeries->SetFileNames( fileNames ); + try { + readerSeries->Update(); + } catch (itk::ExceptionObject &excp) { + std::cerr << "Error: Exception thrown while reading the DICOM model file !!" << std::endl; + std::cerr << excp << std::endl; + } + + // update output dicom keys/tags + typename ReaderSeriesType::DictionaryRawPointer inputDict = (*(readerSeries->GetMetaDataDictionaryArray()))[0]; + typename ReaderSeriesType::DictionaryArrayType outputArray; + typename ReaderSeriesType::DictionaryRawPointer outputDict = new typename ReaderSeriesType::DictionaryType; + CopyDictionary (*inputDict, *outputDict); // origin typename InputImageType::PointType origin = image->GetOrigin(); + value.str(""); + value<(*outputDict, "0020|0032", value.str()); DD(origin); // size @@ -162,24 +189,34 @@ Image2DicomDoseGenericFilter::UpdateWithDimAndPixelType() int NbCols=imageSize[0]; // col int NbRows=imageSize[1]; // row int NbFrames=imageSize[2]; // frame + itk::EncapsulateMetaData(*outputDict, "0028|0008", NumberToString(NbFrames)); + itk::EncapsulateMetaData(*outputDict, "0028|0010", NumberToString(NbRows)); + itk::EncapsulateMetaData(*outputDict, "0028|0011", NumberToString(NbCols)); DD(NbCols); DD(NbRows); DD(NbFrames); // spacing typename InputImageType::SpacingType Spacing = image->GetSpacing(); + value.str(""); + value<(*outputDict, "0028|0030", value.str()); + value.str(""); + value<(*outputDict, "0018|0050", value.str()); DD(Spacing); // offset float offset = 0.; - std::stringstream strOffset; - strOffset << offset; + value.str(""); + value << offset; for (int i=1; i(*outputDict, "3004|000c", value.str()); + DD(value.str()); // scaling float highestValue=pow(10,-10); @@ -188,8 +225,11 @@ Image2DicomDoseGenericFilter::UpdateWithDimAndPixelType() //DD(out.Get()); if (out.Get()>highestValue) highestValue=out.Get(); } - double doseScaling = highestValue/(pow(2,16)-1); - DD(doseScaling); + double doseScaling = 0.0003080821;//highestValue/(pow(2,16)-1); + value.str(""); + value<(*outputDict, "3004|000e", value.str()); + DD(value.str()); // image data /*std::vector ImageData; @@ -222,43 +262,10 @@ Image2DicomDoseGenericFilter::UpdateWithDimAndPixelType() } DD(ImageData.size());*/ - // Read Dicom model file - typename ReaderSeriesType::Pointer readerSeries = ReaderSeriesType::New(); - ImageIOType::Pointer gdcmIO = ImageIOType::New(); - std::string filename_out = m_ArgsInfo.output_arg; - gdcmIO->LoadPrivateTagsOn(); - gdcmIO->KeepOriginalUIDOn(); - typename ReaderSeriesType::FileNamesContainer fileNames; - fileNames.push_back(m_ArgsInfo.DicomInputFile_arg); - readerSeries->SetImageIO( gdcmIO ); - readerSeries->SetFileNames( fileNames ); - try { - readerSeries->Update(); - } catch (itk::ExceptionObject &excp) { - std::cerr << "Error: Exception thrown while reading the DICOM model file !!" << std::endl; - std::cerr << excp << std::endl; - } - - // update output dicom keys/tags - // string for distinguishing items inside sequence: - const std::string ITEM_ENCAPSULATE_STRING("DICOM_ITEM_ENCAPSULATE"); - std::string tempString = ITEM_ENCAPSULATE_STRING + "01"; - typename ReaderSeriesType::DictionaryRawPointer inputDict = (*(readerSeries->GetMetaDataDictionaryArray()))[0]; - typename ReaderSeriesType::DictionaryArrayType outputArray; - typename ReaderSeriesType::DictionaryRawPointer outputDict = new typename ReaderSeriesType::DictionaryType; - CopyDictionary (*inputDict, *outputDict); - itk::EncapsulateMetaData(*outputDict, "0020|0032", NumberToString(origin)); - itk::EncapsulateMetaData(*outputDict, "0028|0008", NumberToString(NbFrames)); - itk::EncapsulateMetaData(*outputDict, "0028|0010", NumberToString(NbRows)); - itk::EncapsulateMetaData(*outputDict, "0028|0011", NumberToString(NbCols)); - itk::EncapsulateMetaData(*outputDict, "0028|0030", NumberToString(Spacing)); - itk::EncapsulateMetaData(*outputDict, "3004|000e", NumberToString(doseScaling)); - itk::EncapsulateMetaData(*outputDict, "3004|000c", strOffset.str()); - outputArray.push_back(outputDict); - // Output directory and filenames typedef itk::ImageSeriesWriter WriterSerieType; typename WriterSerieType::Pointer writerSerie = WriterSerieType::New(); + outputArray.push_back(outputDict); writerSerie->SetInput( image ); writerSerie->SetImageIO( gdcmIO ); typename ReaderSeriesType::FileNamesContainer fileNamesOutput;