<div dir="ltr">I figured how to rotate a DICOM Series in a directory, here's my code, however, I get white images as a result, I'm not sure what I'm missing?<div><br></div><div><div>#include "itkImage.h"</div><div>#include "itkResampleImageFilter.h"</div><div>#include "itkAffineTransform.h"</div><div>#include "itkGDCMImageIO.h"</div><div><br></div><div>//Para las series</div><div>#include "itkGDCMSeriesFileNames.h"</div><div>#include "itkImageSeriesReader.h"</div><div>#include "itkImageSeriesWriter.h"</div><div>#include "itkGDCMSeriesFileNames.h"</div><div>#include "itkNumericSeriesFileNames.h"</div><div><br></div><div>int main( int argc, char * argv[] )</div><div>{</div><div><span class="" style="white-space:pre">  </span>if( argc < 4 )</div><div><span class="" style="white-space:pre">  </span>{</div><div><span class="" style="white-space:pre">          </span>std::cerr << "Usage: " << std::endl;</div><div><span class="" style="white-space:pre">         </span>std::cerr << argv[0] << " Directorio_Entrada Directorio_Salida Grados_Rotacion" << std::endl;</div><div><span class="" style="white-space:pre">          </span>return EXIT_FAILURE;</div><div><span class="" style="white-space:pre">       </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>const unsigned int InputDimension = 3;</div><div><span class="" style="white-space:pre">     </span>const unsigned int OutputDimension = 2;</div><div><span class="" style="white-space:pre">    </span>typedef signed short PixelType;</div><div><span class="" style="white-space:pre">    </span>typedef itk::Image< PixelType, InputDimension >    InputImageType;</div><div><span class="" style="white-space:pre"> </span>typedef itk::Image< PixelType, OutputDimension >    OutputImageType;</div><div><span class="" style="white-space:pre">       </span>typedef itk::ImageSeriesReader< InputImageType >    ReaderType;</div><div><span class="" style="white-space:pre">    </span>typedef itk::GDCMImageIO    ImageIOType;</div><div><span class="" style="white-space:pre"> </span>typedef itk::GDCMSeriesFileNames    InputNamesGeneratorType;</div><div><span class="" style="white-space:pre">     </span>typedef itk::NumericSeriesFileNames    OutputNamesGeneratorType;</div><div><span class="" style="white-space:pre"> </span>typedef itk::ImageSeriesWriter< InputImageType, OutputImageType >    SeriesWriterType;</div><div><span class="" style="white-space:pre">     </span>typedef itk::ResampleImageFilter< InputImageType, InputImageType ></div><div><span class="" style="white-space:pre">           </span>ResampleFilterType;</div><div><span class="" style="white-space:pre">        </span>typedef itk::LinearInterpolateImageFunction<InputImageType, double > InterpolatorType;</div><div><br></div><div><span class="" style="white-space:pre">      </span>ImageIOType::Pointer gdcmIO = ImageIOType::New();</div><div><span class="" style="white-space:pre">  </span>InputNamesGeneratorType::Pointer inputNames = InputNamesGeneratorType::New();</div><div><span class="" style="white-space:pre">      </span>inputNames->SetInputDirectory( argv[1] );</div><div><span class="" style="white-space:pre">       </span>const ReaderType::FileNamesContainer & filenames = </div><div><span class="" style="white-space:pre">           </span>inputNames->GetInputFileNames();</div><div><br></div><div><span class="" style="white-space:pre">       </span>ReaderType::Pointer reader = ReaderType::New();</div><div><br></div><div><span class="" style="white-space:pre">   </span>reader->SetImageIO( gdcmIO );</div><div><span class="" style="white-space:pre">   </span>reader->SetFileNames( filenames );</div><div><span class="" style="white-space:pre">      </span>try</div><div><span class="" style="white-space:pre">        </span>{</div><div><span class="" style="white-space:pre">          </span>reader->Update();</div><div><span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span>catch (itk::ExceptionObject &excp)</div><div><span class="" style="white-space:pre">     </span>{</div><div><span class="" style="white-space:pre">          </span>std::cerr << "Exception thrown while reading the series" << std::endl;</div><div><span class="" style="white-space:pre">               </span>std::cerr << excp << std::endl;</div><div><span class="" style="white-space:pre">                </span>return EXIT_FAILURE;</div><div><span class="" style="white-space:pre">       </span>}</div><div><br></div><div><br></div><div><span class="" style="white-space:pre">        </span>const double angleInDegrees = atof( argv[3] );</div><div><br></div><div><span class="" style="white-space:pre">    </span>typedef itk::AffineTransform< double, InputDimension > TransformType; //usado para mapear el espacio de entrada con el espacio de salida</div><div><span class="" style="white-space:pre">     </span>TransformType::Pointer transform = TransformType::New();</div><div><span class="" style="white-space:pre">   </span>InterpolatorType::Pointer interpolator = InterpolatorType::New();</div><div><br></div><div><br></div><div><span class="" style="white-space:pre">        </span>const InputImageType::PointType & origin = reader->GetOutput()->GetOrigin();</div><div><span class="" style="white-space:pre">     </span>const InputImageType::SpacingType& inputSpacing =</div><div><span class="" style="white-space:pre">              </span>reader->GetOutput()->GetSpacing();</div><div><span class="" style="white-space:pre">   </span>const InputImageType::RegionType& inputRegion =</div><div><span class="" style="white-space:pre">                </span>reader->GetOutput()->GetLargestPossibleRegion();</div><div><span class="" style="white-space:pre">     </span>const InputImageType::SizeType& inputSize =</div><div><span class="" style="white-space:pre">            </span>inputRegion.GetSize();</div><div><br></div><div><span class="" style="white-space:pre">    </span>std::cout << "The input series in directory " << argv[1]</div><div><span class="" style="white-space:pre">     </span><< " has " << filenames.size() << " files with spacing "</div><div><span class="" style="white-space:pre">             </span><< inputSpacing</div><div><span class="" style="white-space:pre">              </span><< std::endl;</div><div><br></div><div><span class="" style="white-space:pre">       </span>transform->SetIdentity();</div><div><br></div><div><span class="" style="white-space:pre">      </span>ResampleFilterType::Pointer filter = ResampleFilterType::New();</div><div><span class="" style="white-space:pre">    </span>filter->SetInput( reader->GetOutput() );</div><div><span class="" style="white-space:pre">     </span>filter->SetInterpolator( interpolator );</div><div><span class="" style="white-space:pre">        </span>filter->SetOutputOrigin( reader->GetOutput()->GetOrigin() );</div><div><span class="" style="white-space:pre">      </span>filter->SetOutputSpacing( inputSpacing );</div><div><span class="" style="white-space:pre">       </span>filter->SetOutputDirection( reader->GetOutput()->GetDirection() );</div><div><span class="" style="white-space:pre">        </span>filter->SetSize( inputSize );</div><div><span class="" style="white-space:pre">   </span>filter->SetDefaultPixelValue(100); //Pixel por defecto de lo que queda fuera de la imagen cuando se rota</div><div><span class="" style="white-space:pre">        </span>//filter->Update();</div><div><br></div><div><span class="" style="white-space:pre">    </span>TransformType::OutputVectorType translation1;</div><div><span class="" style="white-space:pre">      </span>const double imageCenterX = origin[0] + inputSpacing[0] * inputSize[0] / 2.0;</div><div><span class="" style="white-space:pre">      </span>const double imageCenterY = origin[1] + inputSpacing[1] * inputSize[1] / 2.0;</div><div><span class="" style="white-space:pre">      </span>translation1[0] = -imageCenterX;</div><div><span class="" style="white-space:pre">   </span>translation1[1] = -imageCenterY;</div><div><span class="" style="white-space:pre">   </span>transform->Translate( translation1 );</div><div><span class="" style="white-space:pre">   </span>// Software Guide : EndCodeSnippet</div><div><span class="" style="white-space:pre"> </span>std::cout << "imageCenterX = " << imageCenterX << std::endl;</div><div><span class="" style="white-space:pre">   </span>std::cout << "imageCenterY = " << imageCenterY << std::endl;</div><div><br></div><div><span class="" style="white-space:pre">  </span>const double degreesToRadians = std::atan(1.0) / 45.0;</div><div><span class="" style="white-space:pre">     </span>const double angle = angleInDegrees * degreesToRadians;</div><div><span class="" style="white-space:pre">    </span>transform->Rotate2D( -angle, false );</div><div><br></div><div><span class="" style="white-space:pre">  </span>TransformType::OutputVectorType translation2;</div><div><span class="" style="white-space:pre">      </span>translation2[0] = imageCenterX;</div><div><span class="" style="white-space:pre">    </span>translation2[1] = imageCenterY;</div><div><span class="" style="white-space:pre">    </span>transform->Translate( translation2, false );</div><div><span class="" style="white-space:pre">    </span>filter->SetTransform( transform );</div><div><span class="" style="white-space:pre">      </span>filter->Update();</div><div><br></div><div><br></div><div><span class="" style="white-space:pre">     </span>// Generate the file names</div><div><span class="" style="white-space:pre"> </span>itksys::SystemTools::MakeDirectory( argv[2] );</div><div><span class="" style="white-space:pre">     </span>OutputNamesGeneratorType::Pointer outputNames = OutputNamesGeneratorType::New();</div><div><span class="" style="white-space:pre">   </span>std::string seriesFormat(argv[2]);</div><div><span class="" style="white-space:pre"> </span>seriesFormat = seriesFormat + "/" + "IM%d.dcm";</div><div><span class="" style="white-space:pre">        </span>outputNames->SetSeriesFormat (seriesFormat.c_str());</div><div><span class="" style="white-space:pre">    </span>outputNames->SetStartIndex (1);</div><div><span class="" style="white-space:pre"> </span>outputNames->SetEndIndex (230); //Rectificar</div><div><br></div><div><span class="" style="white-space:pre">   </span>SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();</div><div><span class="" style="white-space:pre">  </span>seriesWriter->SetInput( filter->GetOutput() );</div><div><span class="" style="white-space:pre">       </span>seriesWriter->SetImageIO( gdcmIO );</div><div><span class="" style="white-space:pre">     </span>seriesWriter->SetFileNames( outputNames->GetFileNames() );</div><div><span class="" style="white-space:pre">   </span>//seriesWriter->SetMetaDataDictionaryArray( &outputArray );</div><div><span class="" style="white-space:pre"> </span>try</div><div><span class="" style="white-space:pre">        </span>{</div><div><span class="" style="white-space:pre">          </span>seriesWriter->Update();</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre">  </span>catch( itk::ExceptionObject & excp )</div><div><span class="" style="white-space:pre">   </span>{</div><div><span class="" style="white-space:pre">          </span>std::cerr << "Exception thrown while writing the series " << std::endl;</div><div><span class="" style="white-space:pre">              </span>std::cerr << excp << std::endl;</div><div><span class="" style="white-space:pre">                </span>return EXIT_FAILURE;</div><div><span class="" style="white-space:pre">       </span>}</div><div>}</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 14, 2014 at 10:28 AM, Matias Montroull <span dir="ltr"><<a href="mailto:matimontg@gmail.com" target="_blank">matimontg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm having hard times following the code in the example. RIght now I have been able to rotate a dcm file one at a time, now I would like to input a directory and output another directory with  the rotated images, I would need some guidance for this task.<div>Can I just set the input as directory instead of a file for example?</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 13, 2014 at 3:26 PM, Matias Montroull <span dir="ltr"><<a href="mailto:matimontg@gmail.com" target="_blank">matimontg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks Matt, I'll give it a try</div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 13, 2014 at 2:37 PM, Matt McCormick <span dir="ltr"><<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>Hi Matias,<br>
<br>
This example may have a hint on how to write a series [1].<br>
<br>
HTH,<br>
Matt<br>
<br>
[1] <a href="http://itk.org/Doxygen/html/IO_2ImageReadDicomSeriesWrite_8cxx-example.html" target="_blank">http://itk.org/Doxygen/html/IO_2ImageReadDicomSeriesWrite_8cxx-example.html</a><br>
<br>
</span><div><div>On Thu, Nov 13, 2014 at 12:18 PM, Matias Montroull <<a href="mailto:matimontg@gmail.com" target="_blank">matimontg@gmail.com</a>> wrote:<br>
> Now I have another question. This example is just for one file, is there a<br>
> way to do it for a directory containing a set of DICOM files?<br>
><br>
> On Thu, Nov 13, 2014 at 2:16 PM, Matias Montroull <<a href="mailto:matimontg@gmail.com" target="_blank">matimontg@gmail.com</a>><br>
> wrote:<br>
>><br>
>> never mind, it was my bad. The InputPixelType was unsigned char and should<br>
>> have been unsigned short<br>
>><br>
>> On Thu, Nov 13, 2014 at 2:14 PM, Matias Montroull <<a href="mailto:matimontg@gmail.com" target="_blank">matimontg@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> Bradley, as soon as I enter this line of code:<br>
>>><br>
>>> typedef itk::GDCMImageIO ImageIOType;<br>
>>> ImageIOType::Pointer gdcmImageIO = ImageIOType::New();<br>
>>> writer->SetImageIO(gdcmImageIO);<br>
>>><br>
>>> I get a bad image as result.. any ideas what could it be?<br>
>>><br>
>>> On Thu, Nov 13, 2014 at 11:36 AM, Bradley Lowekamp<br>
>>> <<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>> wrote:<br>
>>>><br>
>>>> Hello again,<br>
>>>><br>
>>>> This is a non-trivial task where caution in needed to determine which<br>
>>>> tags should be copied. But here is a basic example here:<br>
>>>> <a href="http://itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM" target="_blank">http://itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM</a><br>
>>>><br>
>>>> Brad<br>
>>>><br>
>>>> On Nov 13, 2014, at 9:30 AM, Matias Montroull <<a href="mailto:matimontg@gmail.com" target="_blank">matimontg@gmail.com</a>><br>
>>>> wrote:<br>
>>>><br>
>>>> I have one more question, it seems the writer method removes lot of tags<br>
>>>> from the image, is there an option to keep the original tags such as patient<br>
>>>> name, model, manufacture etc?<br>
>>>><br>
>>>> On Thu, Nov 13, 2014 at 11:27 AM, Matias Montroull <<a href="mailto:matimontg@gmail.com" target="_blank">matimontg@gmail.com</a>><br>
>>>> wrote:<br>
>>>>><br>
>>>>> Bradley, I must say you're the man! that did the trick, thanks a lot!<br>
>>>>><br>
>>>>> On Thu, Nov 13, 2014 at 10:59 AM, Bradley Lowekamp<br>
>>>>> <<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>> wrote:<br>
>>>>>><br>
>>>>>> Hello,<br>
>>>>>><br>
>>>>>> Check out the ImageToImageFilter::SetDefaultPixelValue method [1].<br>
>>>>>><br>
>>>>>> Brad<br>
>>>>>><br>
>>>>>> [1]<br>
>>>>>> <a href="http://www.itk.org/Doxygen/html/classitk_1_1ResampleImageFilter.html#a227397f3786a0ec4d3107cb73033b4be" target="_blank">http://www.itk.org/Doxygen/html/classitk_1_1ResampleImageFilter.html#a227397f3786a0ec4d3107cb73033b4be</a><br>
>>>>>><br>
>>>>>> On Nov 13, 2014, at 8:56 AM, Matias Montroull <<a href="mailto:matimontg@gmail.com" target="_blank">matimontg@gmail.com</a>><br>
>>>>>> wrote:<br>
>>>>>><br>
>>>>>> Hi,<br>
>>>>>><br>
>>>>>> I'm running this example:<br>
>>>>>><br>
>>>>>> <a href="http://www.itk.org/Doxygen/html/Filtering_2ResampleImageFilter3_8cxx-example.html" target="_blank">http://www.itk.org/Doxygen/html/Filtering_2ResampleImageFilter3_8cxx-example.html</a><br>
>>>>>><br>
>>>>>> and I'm getting this result which is fine but I need the white<br>
>>>>>> sections left due to the rotation to be black. how can I achieve this?<br>
>>>>>><br>
>>>>>> <Capture.JPG><br>
>>>>>><br>
>>>>>> _____________________________________<br>
>>>>>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>>>>>><br>
>>>>>> Visit other Kitware open-source projects at<br>
>>>>>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>>>>>><br>
>>>>>> Kitware offers ITK Training Courses, for more information visit:<br>
>>>>>> <a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
>>>>>><br>
>>>>>> Please keep messages on-topic and check the ITK FAQ at:<br>
>>>>>> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
>>>>>><br>
>>>>>> Follow this link to subscribe/unsubscribe:<br>
>>>>>> <a href="http://public.kitware.com/mailman/listinfo/insight-users" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br>
>>>>>><br>
>>>>>><br>
>>>>><br>
>>>><br>
>>>><br>
>>><br>
>><br>
><br>
><br>
> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/insight-users" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br>
><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>