<div dir="ltr">Hi,<div><br></div><div>I have the following code that I would like to use in C#. Since it is ITK, it's coded in C++ so I was wondering if I could create a DLL that can be used in C# and then call the function as it was a class, pass parameters and use the method?</div><div><br></div><div>All I need is to pass 3 parameters to the function (which is a function to rotate images)</div><div><br></div><div>here's the code:</div><div><br></div><div><div>#include "itkImage.h"</div><div>#include "itkImageFileReader.h"</div><div>#include "itkImageFileWriter.h"</div><div>#include "itkResampleImageFilter.h"</div><div>#include "itkAffineTransform.h"</div><div>#include "itkGDCMImageIO.h"</div><div><br></div><div>int main( int argc, char * argv[] )</div><div>{</div><div>if( argc < 4 )</div><div>{</div><div>std::cerr << "Usage: " << std::endl;</div><div>std::cerr << argv[0] << " inputImageFile outputImageFile degrees" << std::endl;</div><div>return EXIT_FAILURE;</div><div>}</div><div><br></div><div>const unsigned int Dimension = 2; //imagen 2D</div><div>typedef signed short InputPixelType;</div><div>typedef signed short OutputPixelType;</div><div>typedef itk::Image< InputPixelType, Dimension > InputImageType;</div><div>typedef itk::Image< OutputPixelType, Dimension > OutputImageType;</div><div>typedef itk::ImageFileReader< InputImageType > ReaderType;</div><div>typedef itk::ImageFileWriter< OutputImageType > WriterType;</div><div>ReaderType::Pointer reader = ReaderType::New(); //lo que lee</div><div>WriterType::Pointer writer = WriterType::New(); //lo que escribe</div><div>reader->SetFileName( argv[1] ); //primer argumento</div><div>writer->SetFileName( argv[2] ); //segundo argumento</div><div><br></div><div>typedef itk::GDCMImageIO ImageIOType;</div><div>ImageIOType::Pointer gdcmImageIO = ImageIOType::New();</div><div>reader->SetImageIO( gdcmImageIO );</div><div><br></div><div><br></div><div>const double angleInDegrees = atof( argv[3] ); //angulo de rotación</div><div><br></div><div>typedef itk::ResampleImageFilter<InputImageType, OutputImageType > FilterType; //Filtro</div><div>FilterType::Pointer filter = FilterType::New();</div><div><br></div><div>typedef itk::AffineTransform< double, Dimension > TransformType; //usado para mapear el espacio de entrada con el espacio de salida</div><div>TransformType::Pointer transform = TransformType::New();</div><div><br></div><div>typedef itk::LinearInterpolateImageFunction<InputImageType, double > InterpolatorType;</div><div>InterpolatorType::Pointer interpolator = InterpolatorType::New();</div><div>filter->SetInterpolator( interpolator );</div><div>filter->SetDefaultPixelValue(0); //Pixel por defecto de lo que queda fuera de la imagen cuando se rota</div><div><br></div><div>reader->Update();</div><div><br></div><div>const InputImageType * inputImage = reader->GetOutput();</div><div>const InputImageType::SpacingType & spacing = inputImage->GetSpacing();</div><div>const InputImageType::PointType & origin = inputImage->GetOrigin();</div><div>InputImageType::SizeType size =</div><div>inputImage->GetLargestPossibleRegion().GetSize();</div><div>filter->SetOutputOrigin( origin );</div><div>filter->SetOutputSpacing( spacing );</div><div>filter->SetOutputDirection( inputImage->GetDirection() );</div><div>filter->SetSize( size );</div><div><br></div><div>filter->SetInput( reader->GetOutput() );</div><div>writer->SetInput( filter->GetOutput() );</div><div>writer->UseInputMetaDataDictionaryOff();</div><div>writer->SetImageIO(gdcmImageIO);</div><div> TransformType::OutputVectorType translation1;</div><div>const double imageCenterX = origin[0] + spacing[0] * size[0] / 2.0;</div><div>const double imageCenterY = origin[1] + spacing[1] * size[1] / 2.0;</div><div>translation1[0] = -imageCenterX;</div><div>translation1[1] = -imageCenterY;</div><div>transform->Translate( translation1 );</div><div>// Software Guide : EndCodeSnippet</div><div>std::cout << "imageCenterX = " << imageCenterX << std::endl;</div><div>std::cout << "imageCenterY = " << imageCenterY << std::endl;</div><div><br></div><div>const double degreesToRadians = std::atan(1.0) / 45.0;</div><div>const double angle = angleInDegrees * degreesToRadians;</div><div>transform->Rotate2D( -angle, false );</div><div><br></div><div>TransformType::OutputVectorType translation2;</div><div>translation2[0] = imageCenterX;</div><div>translation2[1] = imageCenterY;</div><div>transform->Translate( translation2, false );</div><div>filter->SetTransform( transform );</div><div><br></div><div>try</div><div>{</div><div>writer->Update();</div><div>}</div><div>catch( itk::ExceptionObject & excep )</div><div>{</div><div>std::cerr << "Exception caught !" << std::endl;</div><div>std::cerr << excep << std::endl;</div><div>}</div><div>// Software Guide : EndCodeSnippet</div><div>return EXIT_SUCCESS;</div><div>}</div></div><div><br></div></div>