升采样 重置大小
//函数化 升采样 重置大小
void Resize(ImageType::Pointer input,ImageType::Pointer src,ImageType::Pointer* dst)
{
std::cout <<"----升采样----"<< std::endl;
typedef itk::ResampleImageFilter<ImageType, ImageType> ResampleImageFilterType;
ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
resample->SetInput(input);
typedef itk::AffineTransform<double,2> TransformType;
TransformType::Pointer transform = TransformType::New();
resample->SetTransform(transform);
typedef itk::NearestNeighborInterpolateImageFunction<ImageType,double> InterpolatorType;
InterpolatorType::Pointer interpolator = InterpolatorType::New();
resample->SetInterpolator(interpolator);
resample->SetDefaultPixelValue(0);
resample->SetSize(src->GetLargestPossibleRegion().GetSize());
resample->SetOutputSpacing(src->GetSpacing());
resample->SetOutputOrigin(src->GetOrigin());
ImageType2D::DirectionType direction;
direction.SetIdentity();
resample->SetOutputDirection(direction);
try
{
resample->UpdateLargestPossibleRegion();
}
catch( itk::ExceptionObject & exp )
{
cerr << "Exception caught !" << std::endl;
cerr << exp << std::endl;
}
*dst = resample->GetOutput();
}
本文介绍了一种基于ITK库的升采样图像处理方法,通过定义一个函数来实现图像的升采样重置大小。该方法使用了最近邻插值,并确保输出图像的方向、原点及像素值等参数与目标图像一致。
652

被折叠的 条评论
为什么被折叠?



