<div dir="ltr">Yes, this is what I would need to migrate to C#:<div>It basically reads a dicom directory and performs rotation on the volume, then writes the resulting images back to a directory, copying the tags from the original images.<br><div><br></div><div><div>#include "itkImage.h"</div><div>#include "itkGDCMImageIO.h"</div><div>#include "itkGDCMSeriesFileNames.h"</div><div>#include "itkImageSeriesReader.h"</div><div>#include "itkResampleImageFilter.h"</div><div>#include "itkEuler3DTransform.hxx"</div><div>#include "gdcmUIDGenerator.h"</div><div><br></div><div>#include "itkImageFileWriter.h"</div><div>#include "itkImageSeriesWriter.h"</div><div>#include "itkNumericSeriesFileNames.h"</div><div>#include "itkTranslationTransform.h"</div><div>#include "string.h";</div><div>#include <itkSliceIterator.h></div><div><br></div><div>#include <iostream></div><div>#include <string></div><div>#include <fstream></div><div><br></div><div><br></div><div><br></div><div>static void CopyDictionary(itk::MetaDataDictionary &fromDict,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::MetaDataDictionary &toDict);</div><div><br></div><div>int main(int argc, char* argv[])</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if (argc < 8)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cerr << "Uso: " << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cerr << argv[0] << " Directorio_A_Rotar DirectorioResultante Gamma Beta Alfa CentroRotacionX CentroRotacionY CentroRotacionZ"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span><< std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef signed short PixelType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>const unsigned int Dimension = 3;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>const unsigned int Dimension_Serie = 2;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::Image< PixelType, Dimension > ImageType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::Image<PixelType, Dimension_Serie> ImageType_Serie;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::ImageSeriesReader< ImageType > ReaderType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ReaderType::Pointer reader = ReaderType::New();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::GDCMImageIO ImageIOType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ImageIOType::Pointer gdcmIO = ImageIOType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reader->SetImageIO(gdcmIO);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::GDCMSeriesFileNames NamesGeneratorType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>nameGenerator->SetUseSeriesDetails(true);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>nameGenerator->AddSeriesRestriction("0008|0021");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>nameGenerator->SetDirectory(argv[1]);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>try</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << std::endl << "The directory: " << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << std::endl << argv[1] << std::endl << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << "Contains the following DICOM Series: ";</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << std::endl << std::endl;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef std::vector< std::string > SeriesIdContainer;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>while (seriesItr != seriesEnd)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << seriesItr->c_str() << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>++seriesItr;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string seriesIdentifier;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesIdentifier = seriesUID.begin()->c_str();</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << std::endl << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << "Now reading series: " << std::endl << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << seriesIdentifier << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << std::endl << std::endl;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef std::vector< std::string > FileNamesContainer;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FileNamesContainer fileNames;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>fileNames = nameGenerator->GetFileNames(seriesIdentifier);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reader->SetFileNames(fileNames);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>try</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reader->Update();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>catch (itk::ExceptionObject &ex)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << ex << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>const ImageType * inputImage = reader->GetOutput();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>/*int numerodedicoms = inputImage->GetLargestPossibleRegion().GetSize()[2];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>int dicomcentral = numerodedicoms / 2;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << "Dimenion " << dicomcentral << std::endl;*/</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//itk::EncapsulateMetaData<std::string>(dictionary, "0020|0032","-208\\-236\\66");</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::ResampleImageFilter<ImageType, ImageType> FilterType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FilterType::Pointer FiltroResample = FilterType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->SetInput(reader->GetOutput());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::LinearInterpolateImageFunction<ImageType, double > InterpolatorType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>InterpolatorType::Pointer interpolator = InterpolatorType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->SetInterpolator(interpolator);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->SetOutputDirection(inputImage->GetDirection());</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->SetOutputOrigin(inputImage->GetOrigin());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ImageType::SizeType inputSize = inputImage->GetLargestPossibleRegion().GetSize();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->SetSize(inputSize);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>const ImageType::SpacingType& inputSpacing = inputImage->GetSpacing();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->SetOutputSpacing(inputSpacing);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->SetDefaultPixelValue(-1000); //Cambiar por un parametro</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::Euler3DTransform< double > TransformType; //Transform</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>TransformType::Pointer transform = TransformType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>double alfa, beta, gamma, centro_rotacion_X, centro_rotacion_Y, centro_rotacion_Z;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>gamma = atof(argv[3]); </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>beta= atof(argv[4]);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>alfa = atof(argv[5]);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>centro_rotacion_X = atof(argv[6]);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>centro_rotacion_Y = atof(argv[7]);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>centro_rotacion_Z = atof(argv[8]);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>transform->SetRotation(gamma, beta, alfa); //Radianes en el siguiente orden en ITK: Gamma, Beta, Alfa | Ibarra</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//double centro[3] = { -14.8371, -54.9443, 175.75 }; //XmmPromedio, YmmPromedio, Z Central (mm): Leer directorio y tomar la del medio</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>double centro[3] = { centro_rotacion_X, centro_rotacion_Y, centro_rotacion_Z }; //XmmPromedio, YmmPromedio, Z Central (mm): Leer directorio y tomar la del medio</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>transform->SetCenter(centro);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << "Centro: " << std::endl << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << transform->GetCenter() << std::endl;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->SetTransform(transform);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//FiltroResample->SetMetaDataDictionary(dictionary);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>try</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->Update();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>catch (itk::ExceptionObject &ex)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ReaderType::DictionaryRawPointer inputDict = (*(reader->GetMetaDataDictionaryArray()))[0];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ReaderType::DictionaryArrayType outputArray;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//std::cout << "array: " << std::endl << outputArray[0] << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// To keep the new series in the same study as the original we need</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// to keep the same study UID. But we need new series and frame of</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// reference UID's.</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>gdcm::UIDGenerator suid;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//std::string seriesUID = suid.Generate();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>gdcm::UIDGenerator fuid;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string frameOfReferenceUID = fuid.Generate();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string studyUID;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string sopClassUID;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::ExposeMetaData<std::string>(*inputDict, "0020|000d", studyUID);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::ExposeMetaData<std::string>(*inputDict, "0008|0016", sopClassUID);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>gdcmIO->KeepOriginalUIDOn();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>using namespace std;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>double myArray_Z[70]; //Cambiar esto por un argumento que especifica la cantidad de imagenes.</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>double myArray_X[70]; //Cambiar esto por un argumento que especifica la cantidad de imagenes.</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>double myArray_Y[70]; //Cambiar esto por un argumento que especifica la cantidad de imagenes.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ifstream file("file.txt");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if (file.is_open())</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for (int i = 0; i < 70; ++i) //Recordar cambiar por el argumento que especifica cantidad de imagenes</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>file >> myArray_Z[i];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << "valor primer Z array: " << std::endl << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << myArray_Z[0] << std::endl;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for (unsigned int f = 0; f < inputSize[2]; f++)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Create a new dictionary for this slice</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ReaderType::DictionaryRawPointer dict = new ReaderType::DictionaryType;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Copy the dictionary from the first slice</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>CopyDictionary(*inputDict, *dict);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Set the UID's for the study, series, SOP and frame of reference</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0020|000d", studyUID);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//itk::EncapsulateMetaData<std::string>(*dict, "0020|000e", seriesUID);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0020|0052", frameOfReferenceUID);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>gdcm::UIDGenerator sopuid;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string sopInstanceUID = sopuid.Generate();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0008|0018", sopInstanceUID);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0002|0003", sopInstanceUID);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Change fields that are slice specific</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::ostringstream value;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value.str("");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value << f + 1;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Image Number</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0020|0013", value.str());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Series Description - Append new description to current series</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// description</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string oldSeriesDesc;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::ExposeMetaData<std::string>(*inputDict, "0008|103e", oldSeriesDesc);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value.str("");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value << oldSeriesDesc</div><div><span class="Apple-tab-span" style="white-space:pre"> </span><< ": Resampled with pixel spacing "</div><div><span class="Apple-tab-span" style="white-space:pre"> </span><< inputSpacing[0] << ", "</div><div><span class="Apple-tab-span" style="white-space:pre"> </span><< inputSpacing[1] << ", "</div><div><span class="Apple-tab-span" style="white-space:pre"> </span><< inputSpacing[2];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// This is an long string and there is a 64 character limit in the</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// standard</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>unsigned lengthDesc = value.str().length();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string seriesDesc(value.str(), 0,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>lengthDesc > 64 ? 64</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>: lengthDesc);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0008|103e", seriesDesc);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Series Number</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value.str("");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value << 1001;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0020|0011", value.str());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Derivation Description - How this image was derived</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value.str("");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for (int i = 0; i < argc; i++)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value << argv[i] << " ";</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>lengthDesc = value.str().length();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string derivationDesc(value.str(), 0,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>lengthDesc > 1024 ? 1024</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>: lengthDesc);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0008|2111", derivationDesc);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Image Position Patient: This is calculated by computing the</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// physical coordinate of the first pixel in each slice.</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ImageType::PointType position;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ImageType::IndexType index;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>index[0] = 0;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>index[1] = 0;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>index[2] = myArray_Z[f];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FiltroResample->GetOutput()->TransformIndexToPhysicalPoint(index, position);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//El origen que calculamos en el proyecto no se toca. (Origen = origen - average)</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//Cambiamos el ImageOrientationPatient SOLAMENTE si el valor original en la imagen es: 1\0\0\0\1\0. En el caso que se cambia el signo, se debe cambiar el signo del origen</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//value.str("");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//value << -1 << "\\" << 0 << "\\" << 0 << "\\" << 0 << "\\" << -1 << "\\" << 0; //PASAR ESTO POR ARGUMENTO!!!</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//itk::EncapsulateMetaData<std::string>(*dict, "0020|0037", value.str());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value.str("");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value << -235.1629 << "\\" << -195.0557 << "\\" << myArray_Z[f]; //PASAR ESTO POR ARGUMENTO!!! El origen - Centro</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0020|0032", value.str());</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Slice Location: For now, we store the z component of the Image</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Position Patient.</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value.str("");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value << position[2];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0020|1041", value.str());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Slice Thickness: For now, we store the z spacing</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value.str("");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value << inputSpacing[2];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0018|0050",</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value.str());</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Spacing Between Slices</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(*dict, "0018|0088",</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value.str());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Save the dictionary</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>outputArray.push_back(dict);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::ImageFileWriter< ImageType > WriterType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>WriterType::Pointer writer = WriterType::New();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::ImageSeriesWriter< ImageType, ImageType_Serie > SeriesWriterType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesWriter->SetInput(FiltroResample->GetOutput());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>writer->SetFileName(argv[2]);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>writer->SetInput(FiltroResample->GetOutput());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itksys::SystemTools::MakeDirectory("Test"); //PASAR ESTO POR ARGUMENTO!!</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::NumericSeriesFileNames OutputNamesGeneratorType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>OutputNamesGeneratorType::Pointer outputNames = OutputNamesGeneratorType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string seriesFormat("Test"); //PASAR ESTO POR ARGUMENTO!!</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesFormat = seriesFormat + "/" + "IM%d.dcm";</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>outputNames->SetSeriesFormat(seriesFormat.c_str());</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>outputNames->SetStartIndex(1);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>outputNames->SetEndIndex(inputSize[2]);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesWriter->SetImageIO(gdcmIO);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesWriter->SetFileNames(outputNames->GetFileNames());</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesWriter->SetMetaDataDictionaryArray(&outputArray);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << "Escribiendo la imagen como..." << std::endl << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << argv[2] << std::endl << std::endl;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>try</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>writer->Update();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesWriter->Update();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>catch (itk::ExceptionObject &ex)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << ex << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>catch (itk::ExceptionObject &ex)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cout << ex << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_SUCCESS;</div><div><br></div><div>}</div><div><br></div><div>void CopyDictionary(itk::MetaDataDictionary &fromDict, itk::MetaDataDictionary &toDict)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::MetaDataDictionary DictionaryType;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>DictionaryType::ConstIterator itr = fromDict.Begin();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>DictionaryType::ConstIterator end = fromDict.End();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::MetaDataObject< std::string > MetaDataStringType;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>while (itr != end)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::MetaDataObjectBase::Pointer entry = itr->second;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>MetaDataStringType::Pointer entryvalue =</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>dynamic_cast<MetaDataStringType *>(entry.GetPointer());</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if (entryvalue)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string tagkey = itr->first;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string tagvalue = entryvalue->GetMetaDataObjectValue();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(toDict, tagkey, tagvalue);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>++itr;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div>}</div></div><div><br></div><br><div class="gmail_quote"><div dir="ltr">El jue., 30 de mar. de 2017 a la(s) 11:25, Lowekamp, Bradley (NIH/NLM/LHC) [C] [via ITK - Users] <<a href="/user/SendEmail.jtp?type=node&node=38056&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>> escribió:<br></div><blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,
<br class="gmail_msg"><br class="gmail_msg">Writing correct DICOM continues to be a struggle with SimpleITK and ITK. It is generally recommended to directly use GDCM or DCMTK to write a proper DICOM series.
<br class="gmail_msg"><br class="gmail_msg">SimpleITK tries to keep things, well, simple and straight forward. But ITK ties to do some smart things, which get in the way for certain uses with SimpleITK. We are trying to document and develop a nominal set of DICOM output operations that work in SimpleITK.
<br class="gmail_msg"><br class="gmail_msg">Do you have working C++ code that works for your intended operation? Can you share a small section of code which does what you expect it C++?
<br class="gmail_msg"><br class="gmail_msg">Thank,
<br class="gmail_msg">Brad
<br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><div class="m_-4798084068031981746shrinkable-quote gmail_msg"><div class='shrinkable-quote'><br class="gmail_msg">> On Mar 30, 2017, at 8:49 AM, Matias <<a href="http:///user/SendEmail.jtp?type=node&node=38052&i=0" rel="nofollow" link="external" class="gmail_msg" target="_blank">[hidden email]</a>> wrote:
<br class="gmail_msg">>
<br class="gmail_msg">> Hi,
<br class="gmail_msg">>
<br class="gmail_msg">> I've been dealing with ITK for years in C++ and now I would need to use
<br class="gmail_msg">> SimpleITK and C# as far as I can in a new proyect.
<br class="gmail_msg">>
<br class="gmail_msg">> Is the SimpleITK SeriesWriter working for Dicom Files? Last time I tried to
<br class="gmail_msg">> use it I had problems with the DicomTags, these would not copy or there was
<br class="gmail_msg">> no method to copy the tags to the resulting slices.
<br class="gmail_msg">>
<br class="gmail_msg">> Currently, I read a volume of slices, apply rotation and then I need to
<br class="gmail_msg">> write the resulting image as another set of slices AND keeping tag
<br class="gmail_msg">> information such as patient name, etc.
<br class="gmail_msg">>
<br class="gmail_msg">> Thank you,
<br class="gmail_msg">>
<br class="gmail_msg">> Matias.
<br class="gmail_msg">>
<br class="gmail_msg">>
<br class="gmail_msg">>
<br class="gmail_msg">> --
<br class="gmail_msg">> View this message in context: <a href="http://itk-users.7.n7.nabble.com/SimpleITK-Serieswriter-and-DicomTags-tp38050.html" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://itk-users.7.n7.nabble.com/SimpleITK-Serieswriter-and-DicomTags-tp38050.html</a><br class="gmail_msg">> Sent from the ITK - Users mailing list archive at Nabble.com.
<br class="gmail_msg">> _____________________________________
<br class="gmail_msg">> Powered by <a href="http://www.kitware.com" class="gmail_msg" target="_blank" rel="nofollow" link="external">www.kitware.com</a>
<br class="gmail_msg">>
<br class="gmail_msg">> Visit other Kitware open-source projects at
<br class="gmail_msg">> <a href="http://www.kitware.com/opensource/opensource.html" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br class="gmail_msg">>
<br class="gmail_msg">> Kitware offers ITK Training Courses, for more information visit:
<br class="gmail_msg">> <a href="http://www.kitware.com/products/protraining.php" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://www.kitware.com/products/protraining.php</a><br class="gmail_msg">>
<br class="gmail_msg">> Please keep messages on-topic and check the ITK FAQ at:
<br class="gmail_msg">> <a href="http://www.itk.org/Wiki/ITK_FAQ" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br class="gmail_msg">>
<br class="gmail_msg">> Follow this link to subscribe/unsubscribe:
<br class="gmail_msg">> <a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br class="gmail_msg">> _______________________________________________
<br class="gmail_msg">> Community mailing list
</div></div><div class="m_-4798084068031981746shrinkable-quote gmail_msg">> <a href="http:///user/SendEmail.jtp?type=node&node=38052&i=1" rel="nofollow" link="external" class="gmail_msg" target="_blank">[hidden email]</a>
<br class="gmail_msg">> <a href="http://public.kitware.com/mailman/listinfo/community" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://public.kitware.com/mailman/listinfo/community</a></div><br class="gmail_msg">_____________________________________
<br class="gmail_msg">Powered by <a href="http://www.kitware.com" class="gmail_msg" target="_blank" rel="nofollow" link="external">www.kitware.com</a>
<br class="gmail_msg"><br class="gmail_msg">Visit other Kitware open-source projects at
<br class="gmail_msg"><a href="http://www.kitware.com/opensource/opensource.html" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br class="gmail_msg"><br class="gmail_msg">Kitware offers ITK Training Courses, for more information visit:
<br class="gmail_msg"><a href="http://www.kitware.com/products/protraining.php" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://www.kitware.com/products/protraining.php</a><br class="gmail_msg"><br class="gmail_msg">Please keep messages on-topic and check the ITK FAQ at:
<br class="gmail_msg"><a href="http://www.itk.org/Wiki/ITK_FAQ" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br class="gmail_msg"><br class="gmail_msg">Follow this link to subscribe/unsubscribe:
<br class="gmail_msg"><a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="nofollow" link="external" class="gmail_msg" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<hr noshade size="1" color="#cccccc" class="gmail_msg">
<div style="color:#444;font:12px tahoma,geneva,helvetica,arial,sans-serif" class="gmail_msg">
<div style="font-weight:bold" class="gmail_msg">If you reply to this email, your message will be added to the discussion below:</div>
<a href="http://itk-users.7.n7.nabble.com/SimpleITK-Serieswriter-and-DicomTags-tp38050p38052.html" class="gmail_msg" target="_blank" rel="nofollow" link="external">http://itk-users.7.n7.nabble.com/SimpleITK-Serieswriter-and-DicomTags-tp38050p38052.html</a>
</div>
<div style="color:#666;font:11px tahoma,geneva,helvetica,arial,sans-serif;margin-top:.4em;line-height:1.5em" class="gmail_msg">
To unsubscribe from SimpleITK Serieswriter and DicomTags, <a href="" class="gmail_msg" target="_blank" rel="nofollow" link="external">click here</a>.<br class="gmail_msg">
<a href="http://itk-users.7.n7.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" rel="nofollow" style="font:9px serif" class="gmail_msg" target="_blank" link="external">NAML</a>
</div></blockquote></div></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">Matias</div></div>
<br/><hr align="left" width="300" />
View this message in context: <a href="http://itk-users.7.n7.nabble.com/SimpleITK-Serieswriter-and-DicomTags-tp38050p38056.html">Re: [ITK-users] [ITK] SimpleITK Serieswriter and DicomTags</a><br/>
Sent from the <a href="http://itk-users.7.n7.nabble.com/">ITK - Users mailing list archive</a> at Nabble.com.<br/>