Coordinate conversion

I want to convert the image to a polar coordinate system, process it, and then convert it back to the Cartesian coordinate system. How can I do it with itkCartesianToPolarTransform and itkPolarToCartesianTransform? With ResampleImageFilter? But there is a bug when I call SetTransform().

You approach sounds plausible. What is that bug?

Also take a look at:

It seems like useful. I just want to convert a CT image from Cartesian coordinate system to polar coordinate system, and apply some filters.

Can I use itk::CartesianToPolarTransform? It is simple to use.

You should be able to do that. What problems did you encounter?

I used ResampleImageFilter.

constexpr unsigned int Dimension = 3;

  using PixelType = float; using ScalarType = double;
  using ImageType = itk::Image<PixelType, Dimension>;
  using IndexValueType = typename itk::Index<Dimension>::IndexValueType;

  const typename ImageType::Pointer     inputImage = cv::ReadMhdImage<float, 3>("recon.mhd");
  const typename ImageType::RegionType  inputRegion = inputImage->GetLargestPossibleRegion();
  const typename ImageType::SizeType    inputSize = inputRegion.GetSize();
  const typename ImageType::SpacingType inputSpacing = inputImage->GetSpacing();
  const typename ImageType::PointType   inputOrigin = inputImage->GetOrigin();

  typename ImageType::SizeType    outputSize;
  outputSize[0] = 720; outputSize[1] = 720; outputSize[2] = inputSize[2];
  typename ImageType::SpacingType outputSpacing = inputSpacing;
  typename ImageType::PointType   outputOrigin = inputOrigin;

  using PolarTransformType = itk::CartesianToPolarTransform<ScalarType, Dimension>;
  auto polarTransform = PolarTransformType::New();

  itk::Point<ScalarType, Dimension> center;
  itk::ContinuousIndex<ScalarType, Dimension> centerSize;
  centerSize[0] = inputSize[0] / 2;
  centerSize[1] = inputSize[1] / 2;
  centerSize[2] = inputSize[2] / 2;

  center = inputImage->TransformContinuousIndexToPhysicalPoint<ScalarType, ScalarType>(centerSize);
  polarTransform->SetCenter(center);

  using LinearInterpolatorType = itk::LinearInterpolateImageFunction<ImageType, ScalarType>;
  auto interpolator = LinearInterpolatorType::New();

  using ResampleFilterType = itk::ResampleImageFilter<ImageType, ImageType>;
  auto resampleFilter = ResampleFilterType::New();

  resampleFilter->SetInput(inputImage);
  resampleFilter->SetTransform(polarTransform);
  resampleFilter->SetInterpolator(interpolator);
  resampleFilter->SetSize(outputSize);
  resampleFilter->SetOutputSpacing(outputSpacing);
  resampleFilter->SetOutputOrigin(outputOrigin);
  
  auto writer = itk::ImageFileWriter<ImageType>::New();
  writer->SetFileName("polar.mhd");
  writer->SetImageIO(itk::MetaImageIO::New());
  writer->SetInput(resampleFilter->GetOutput());
  writer->Update();

Resampled image and raw image look like this.


The results are not satisfactory

You spherical object is not at the center of your image. If you want that, then you need to determine the center somehow. One option is manually picking the center. Another option is using Hough circle transform.

If the goal is to remove the ring artifacts, this filter may be helpful.