Itk 重新采样有二多种情况,这里说二种情况
1. 输入参数 ,和输出相关数据,输出范围,spacing ;
typedef itk::Image< float, 3 > itkFloatImageType;
typedef itk::ResampleImageFilter < itkFloatImageType, itkFloatImageType > ResampleImageFilter;
ResampleImageFilter::Pointer resampleImageFilter = ResampleImageFilter::New();
typedef itk::LinearInterpolateImageFunction<itkFloatImageType, double> T_Interpolator;
itkFloatImageType::Pointer itkImage;
mitk::CastToItkImage(inputImage, itkImage);
itkFloatImageType::Pointer itkImageOut;
mitk::CastToItkImage(segmentationA, itkImageOut);
itkFloatImageType::SpacingType outputSpacingItk = itkImageOut->GetSpacing();
itkFloatImageType::SizeType outputSizeItk = itkImageOut->GetLargestPossibleRegion().GetSize();
typedef itk::IdentityTransform<double, 3> TransformType;
T_Interpolator::Pointer _pInterpolator = T_Interpolator::New();
resampleImageFilter->SetInput(itkImage);
resampleImageFilter->SetTransform(TransformType::New());
resampleImageFilter->SetInterpolator(_pInterpolator);
resampleImageFilter->SetReferenceImage(itkImageOut);
resampleImageFilter->UseReferenceImageOn();
//resampleImageFilter->UpdateLargestPossibleRegion();
resampleImageFilter->Update();
注意输入是 float
其它类型转 to float
vtkImageData * ToFloatScaleValue(vtkImageData * VtkImageData)
{
Thresholding
vtkSmartPointer<vtkImageThreshold> imageThreshold = vtkSmartPointer<vtkImageThreshold>::New();
imageThreshold->SetInputData(VtkImageData);
imageThreshold->SetOutputScalarTypeToFloat();
imageThreshold->ThresholdByLower(0.2); // range is inclusive but always in double. Precision issue.
imageThreshold->SetOutValue(255);
imageThreshold->SetInValue(0);
imageThreshold->ReleaseDataFlagOn();
imageThreshold->UpdateInformation();
imageThreshold->Update();
return imageThreshold->GetOutput();
}
2. 输入参数 ,输入数据,和输出相关数据, spacing ;需要自己求出 bounds 输出范围
typedef itk::ResampleImageFilter < itkFloatImageType, itkFloatImageType > ResampleImageFilter;
ResampleImageFilter::Pointer resampleImageFilter = ResampleImageFilter::New();
itkFloatImageType::Pointer itkImage;
mitk::CastToItkImage(out, itkImage);
itkFloatImageType::SpacingType outputSpacing;
itkFloatImageType::SizeType inputSize = itkImage->GetLargestPossibleRegion().GetSize();
itkFloatImageType::SizeType outputSize = inputSize;
outputSpacing[0] = itkImage->GetSpacing()[0];
outputSpacing[1] = resampleSpacing;
outputSpacing[2] = itkImage->GetSpacing()[2];
outputSize[1] = inputSize[1] * itkImage->GetSpacing()[1] / outputSpacing[1];
typedef itk::IdentityTransform<double, 3> TransformType;
resampleImageFilter->SetInput(itkImage);
resampleImageFilter->SetSize(outputSize);
resampleImageFilter->SetOutputSpacing(outputSpacing);
resampleImageFilter->SetTransform(TransformType::New());
resampleImageFilter->UpdateLargestPossibleRegion();