12 #ifndef mitkCLResampleImageToReference_cpp 13 #define mitkCLResampleImageToReference_cpp 24 #include "itkLinearInterpolateImageFunction.h" 25 #include "itkWindowedSincInterpolateImageFunction.h" 26 #include "itkNearestNeighborInterpolateImageFunction.h" 27 #include "itkIdentityTransform.h" 28 #include "itkResampleImageFilter.h" 31 template<
typename TPixel,
unsigned int VImageDimension>
38 typedef itk::IdentityTransform<double, VImageDimension> T_Transform;
39 typename T_Transform::Pointer _pTransform = T_Transform::New();
40 _pTransform->SetIdentity();
42 typedef itk::WindowedSincInterpolateImageFunction< InputImageType, VImageDimension> WindowedSincInterpolatorType;
43 typename WindowedSincInterpolatorType::Pointer sinc_interpolator = WindowedSincInterpolatorType::New();
45 typedef itk::LinearInterpolateImageFunction< InputImageType> LinearInterpolateImageFunctionType;
46 typename LinearInterpolateImageFunctionType::Pointer lin_interpolator = LinearInterpolateImageFunctionType::New();
48 typedef itk::NearestNeighborInterpolateImageFunction< InputImageType> NearestNeighborInterpolateImageFunctionType;
49 typename NearestNeighborInterpolateImageFunctionType::Pointer nn_interpolator = NearestNeighborInterpolateImageFunctionType::New();
51 typename InputImageType::Pointer itkMoving = InputImageType::New();
53 typedef itk::ResampleImageFilter<InputImageType, InputImageType> ResampleFilterType;
55 typename ResampleFilterType::Pointer resampler = ResampleFilterType::New();
56 resampler->SetInput(itkMoving);
57 resampler->SetReferenceImage( itkReference );
58 resampler->UseReferenceImageOn();
59 resampler->SetTransform(_pTransform);
63 resampler->SetInterpolator(lin_interpolator);
69 result->InitializeByItk(resampler->GetOutput());
71 MITK_INFO <<
"writing result to: " << ergPath;
76 int main(
int argc,
char* argv[])
87 parser.
setTitle(
"Resample Image To Reference");
88 parser.
setDescription(
"Resamples an image (moving) to an given image (fix) without additional registration.");
91 std::map<std::string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
93 if (parsedArgs.size() == 0)
97 if (parsedArgs.count(
"help") || parsedArgs.count(
"h"))
void setContributor(std::string contributor)
::mitk::Image InputImageType
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false, mitkCommandLineParser::Channel channel=mitkCommandLineParser::Channel::None)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
int main(int argc, char *argv[])
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
void ResampleImageToReferenceFunction(itk::Image< TPixel, VImageDimension > *itkReference, mitk::Image::Pointer moving, std::string ergPath)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)
void setTitle(std::string title)
void setDescription(std::string description)