Hi guys!
im trying to apply euler 3d transformation matrix, to a mapper (a segmentation archive) that i have in dicom format. but when i apply the resampling filter, it seems to smootj the image instead of rotating it… here is my code…
class CommandIterationUpdate : public itk::Command
{
public:
using Self = CommandIterationUpdate;
using Superclass = itk::Command;
using Pointer = itk::SmartPointer<Self>;
itkNewMacro(Self);
protected:
CommandIterationUpdate() = default;
public:
using OptimizerType = itk::RegularStepGradientDescentOptimizerv4<double>;
using OptimizerPointer = const OptimizerType*;
void Execute(itk::Object* caller, const itk::EventObject& event) override
{
Execute((const itk::Object*)caller, event);
}
void Execute(const itk::Object* object, const itk::EventObject& event) override
{
auto optimizer = static_cast<OptimizerPointer>(object);
if (!itk::IterationEvent().CheckEvent(&event))
{
return;
}
std::cout << optimizer->GetCurrentIteration() << " ";
std::cout << optimizer->GetValue() << " ";
std::cout << optimizer->GetCurrentPosition() << std::endl;
}
};
int main(int argc, char* argv[])
{
if (argc < 4)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " fixedImageFile movingImageFile ";
std::cerr << " outputImagefile [differenceBeforeRegistration] ";
std::cerr << " [differenceAfterRegistration] ";
std::cerr << " [sliceBeforeRegistration] ";
std::cerr << " [sliceDifferenceBeforeRegistration] ";
std::cerr << " [sliceDifferenceAfterRegistration] ";
std::cerr << " [sliceAfterRegistration] " << std::endl;
return EXIT_FAILURE;
}
constexpr unsigned int Dimension = 3;
//using PixelType = float;
// using ImageType = itk::Image<PixelType, Dimension>;
// using FixedImageType = itk::Image< PixelType, Dimension >;
//using MovingImageType = itk::Image< PixelType, Dimension >;
using ImageType2 = itk::Image<unsigned short, Dimension>;
using ReaderType = itk::ImageFileReader <ImageType2>;
ReaderType::Pointer reader = ReaderType::New();
using ImageIOType = itk::GDCMImageIO;
ImageIOType::Pointer dicomIO = ImageIOType::New();
reader->SetFileName(argv[4]);
reader->SetImageIO(dicomIO);
reader->Update();
using WritePixelType = unsigned short;
using WriteImageType = itk::Image< WritePixelType, 3 >;
using WriterType = itk::ImageFileWriter< WriteImageType >;
using ResampleFilterType2 = itk::ResampleImageFilter<ImageType2, ImageType2>;
ResampleFilterType2::Pointer resampleFilter = ResampleFilterType2::New();
using TransformType2 = itk::Euler3DTransform <double>;
TransformType2::Pointer euler = TransformType2::New();
TransformType2::ParametersType eulerParameters(6);
eulerParameters[0] = -0.000386475;
eulerParameters[1] = -0.00429389;
eulerParameters[2] = - 0.00356576;
eulerParameters[3] = -0.223939;
eulerParameters[4] = 0.0744373;
eulerParameters[5] = 0.0441257;
euler->SetParameters(eulerParameters);
resampleFilter->SetTransform(euler);
resampleFilter->SetInput(reader->GetOutput());
ImageType2::RegionType region = reader->GetOutput()->GetLargestPossibleRegion();
ImageType2::SizeType size=region.GetSize();
resampleFilter->SetSize(size);
WriterType::Pointer writer2 = WriterType::New();
writer2->SetFileName(argv[5]);
writer2->SetInput(resampleFilter->GetOutput());
writer2->Update();
return EXIT_SUCCESS;
}