From: tbaudier Date: Thu, 25 Jan 2018 14:00:57 +0000 (+0100) Subject: Use ITK-gdcm with clitkImage2DicomDoseGenericFilter X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=103778ec7e0d03e32d9ecfa1306312d32d72ad4c;p=clitk.git Use ITK-gdcm with clitkImage2DicomDoseGenericFilter --- diff --git a/tools/clitkImage2DicomDoseGenericFilter.h b/tools/clitkImage2DicomDoseGenericFilter.h index b1c1193..f94d08a 100644 --- a/tools/clitkImage2DicomDoseGenericFilter.h +++ b/tools/clitkImage2DicomDoseGenericFilter.h @@ -109,6 +109,7 @@ namespace clitk //Usefull functions void CopyDictionary (itk::MetaDataDictionary &fromDict, itk::MetaDataDictionary &toDict); + template std::string NumberToString ( T Number ); } // end namespace clitk diff --git a/tools/clitkImage2DicomDoseGenericFilter.txx b/tools/clitkImage2DicomDoseGenericFilter.txx index a53b541..667340a 100644 --- a/tools/clitkImage2DicomDoseGenericFilter.txx +++ b/tools/clitkImage2DicomDoseGenericFilter.txx @@ -144,6 +144,84 @@ Image2DicomDoseGenericFilter::UpdateWithDimAndPixelType() typedef itk::ImageRegionIterator< InputImageType > IteratorType; typedef itk::GDCMImageIO ImageIOType; + //----------------------------------------------------------------------------- + // opening image input file + typename ReaderType::Pointer reader = ReaderType::New(); + const char * filename = m_ArgsInfo.input_arg; + reader->SetFileName( filename ); + reader->Update(); + typename InputImageType::Pointer image = reader->GetOutput(); + + // origin + typename InputImageType::PointType origin = image->GetOrigin(); + DD(origin); + + // size + typename InputImageType::SizeType imageSize = image->GetLargestPossibleRegion().GetSize(); + //DD(imageSize); + int NbCols=imageSize[0]; // col + int NbRows=imageSize[1]; // row + int NbFrames=imageSize[2]; // frame + DD(NbCols); + DD(NbRows); + DD(NbFrames); + + // spacing + typename InputImageType::SpacingType Spacing = image->GetSpacing(); + DD(Spacing); + + // offset + float offset = 0.; + std::stringstream strOffset; + strOffset << offset; + for (int i=1; iGetRequestedRegion() ); + for (out.GoToBegin(); !out.IsAtEnd(); ++out){ + //DD(out.Get()); + if (out.Get()>highestValue) highestValue=out.Get(); + } + double doseScaling = highestValue/(pow(2,16)-1); + DD(doseScaling); + + // image data + /*std::vector ImageData; + typename InputImageType::IndexType pixelIndex; + int l=0; + unsigned short int pixelValue; + //DD(highestValue); + for (int i=0; iGetPixel(pixelIndex)/doseScaling; + if(float(image->GetPixel(pixelIndex)/doseScaling)>(pow(2,16)-1.)) { + std::cout<<"\n!!!!! WARNING !!!!! pixel index: "< Highest value may become 0"<GetPixel(pixelIndex)); + //DD(image->GetPixel(pixelIndex)/doseScaling); + DD(pixelValue); + std::cout<<"Pixel Value should be equal to "<<(pow(2,16)-1)<<" but should not be 0"<::UpdateWithDimAndPixelType() std::cerr << excp << std::endl; } - - -//----------------------------------------------------------------------------------- -// opening dicom input file - gdcm::Reader reader2; - reader2.SetFileName( m_ArgsInfo.DicomInputFile_arg ); - reader2.Read(); - gdcm::File &mDCMFile = reader2.GetFile(); - gdcm::DataSet &ds = mDCMFile.GetDataSet(); -//mDCMFile.SetMaxSizeLoadEntry(1006384); // important size required, otherwise some data are not loaded -//mDCMFile.AddForceLoadElement(0x7fe0,0x0010); //Load pixel data no matter its size - -std::cout << "File: "<< m_ArgsInfo.DicomInputFile_arg << " loaded !"<< std::endl; - - - -//----------------------------------------------------------------------------- -// opening image input file -typename ReaderType::Pointer reader = ReaderType::New(); -const char * filename = m_ArgsInfo.input_arg; -reader->SetFileName( filename ); -reader->Update(); -typename InputImageType::Pointer image = reader->GetOutput(); - -// origin -typename InputImageType::PointType origin = image->GetOrigin(); -DD(origin); - -// size -typename InputImageType::SizeType imageSize = image->GetLargestPossibleRegion().GetSize(); -//DD(imageSize); -int NbCols=imageSize[0]; // col -int NbRows=imageSize[1]; // row -int NbFrames=imageSize[2]; // frame -DD(NbCols); -DD(NbRows); -DD(NbFrames); - -// spacing -typename InputImageType::SpacingType Spacing = image->GetSpacing(); -DD(Spacing); - -// scaling -float highestValue=pow(10,-10); -IteratorType out( image, image->GetRequestedRegion() ); -for (out.GoToBegin(); !out.IsAtEnd(); ++out){ -//DD(out.Get()); - if (out.Get()>highestValue) highestValue=out.Get(); -} -double doseScaling = highestValue/(pow(2,16)-1); -DD(doseScaling); - -// image data -std::vector ImageData; -typename InputImageType::IndexType pixelIndex; -int l=0; -unsigned short int pixelValue; -//DD(highestValue); -for (int i=0; iGetPixel(pixelIndex)/doseScaling; -if(float(image->GetPixel(pixelIndex)/doseScaling)>(pow(2,16)-1.)) { -std::cout<<"\n!!!!! WARNING !!!!! pixel index: "< Highest value may become 0"<GetPixel(pixelIndex)); -//DD(image->GetPixel(pixelIndex)/doseScaling); -DD(pixelValue); -std::cout<<"Pixel Value should be equal to "<<(pow(2,16)-1)<<" but should not be 0"<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 @@ -271,167 +266,17 @@ doseScaling writerSerie->SetFileNames( fileNamesOutput ); writerSerie->SetMetaDataDictionaryArray(&outputArray); - - - - - - - - - - - - - - - - -//-------------------------------------------------------------- -std::cout<<"\nECRITURE DU FICHIER DICOM !"<Update(); + } catch( itk::ExceptionObject & excp ) { + std::cerr << "Error: Exception thrown while writing the series!!" << std::endl; + std::cerr << excp << std::endl; } -Value = strs.str(); -DE.SetVR( gdcm::VR::US ); -DE.SetByteValue(Value.c_str(), 1); -ds.Insert(DE); -DD(Value.c_str()); -strs.str(""); -/* -// NbCols -b = ((gdcm::SQItem*)mDCMFile)->GetValEntry(0x0028,0x0011); -Value<SetValue(Value.str()); -DD(Value.str()); -Value.str(""); - -// NbRows -b = ((gdcm::SQItem*)mDCMFile)->GetValEntry(0x0028,0x0010); -Value<SetValue(Value.str()); -DD(Value.str()); -Value.str(""); -//DD(Value.str()); - -// NbFrames -b = ((gdcm::SQItem*)mDCMFile)->GetValEntry(0x0028,0x0008); -Value<SetValue(Value.str()); -DD(Value.str()); -Value.str(""); - -// doseScaling -b = ((gdcm::SQItem*)mDCMFile)->GetValEntry(0x3004,0x000e); -Value<SetValue(Value.str()); -DD(Value.str()); -Value.str(""); - -// Spacing X Y -b = ((gdcm::SQItem*)mDCMFile)->GetValEntry(0x0028, 0x0030); -Value<SetValue(Value.str()); -DD(Value.str()); -Value.str(""); - -// Spacing Z ([Grid Frame Offset Vector]) -b = ((gdcm::SQItem*)mDCMFile)->GetValEntry(0x3004, 0x000c); -float offset=0.; -Value<SetValue(Value.str()); -DD(Value.str()); -Value.str(""); -*/ -//ImageData -//bool data = mDCMFile->SetBinEntry(reinterpret_cast( &(ImageData[0]) ) , (int)(sizeof(unsigned short int) * ImageData.size()) , 0x7fe0, 0x0010); -//if (data) std::cout<<"\n DICOM dose data written !"<GetFileType(); -//type=(gdcm::FileType)2; -bool ecriture = mDCMFile->Write (args_info.OutputFile_arg, type); -if (ecriture) std::cout<<"\n DICOM File written !"<Delete(); //--------------------------------------------------------------------------------------- @@ -554,8 +399,8 @@ mDCMFile->Write (args_info.OutputFile_arg, type); //((gdcm::SQItem*)mDCMFile)->RemoveEntry(a); //----------------------------------------------------------------------------------- -std::cout <<"\n## DICOM Image to RT DOSE application is ended..."< std::string NumberToString ( T Number ) +{ + std::ostringstream ss; + ss << Number; + return ss.str(); +} +//--------------------------------------------------------------------------- + + }//end clitk #endif //#define clitkImage2DicomDoseGenericFilter_txx