itk创建新的空图像和复制图像

1. 创建新的空图像

void CustomFunctions::createNewItkImage(
	ImagePointer3D& new_image, 
	const ImageType3D::SpacingType& spacing, 
	const ImageType3D::DirectionType& direction, 
	const ImageType3D::PointType& origin, 
	const ImageType3D::SizeType& size)
{
	ImageType3D::IndexType start;
	start[0] = 0; // x轴起始值
	start[1] = 0; // y轴起始值
	start[2] = 0; // z轴起始值
	ImageType3D::RegionType region;
	region.SetSize(size);
	region.SetIndex(start);
	new_image->SetRegions(region);
	new_image->Allocate();
	new_image->SetSpacing(spacing);
	new_image->SetDirection(direction);
	new_image->SetOrigin(origin);
	short* regionBuffer = new_image->GetBufferPointer();
	for (int x = 0; x < size[0]; x++) {
		for (int y = 0; y < size[1]; y++) {
			for (int z = 0; z < size[2]; z++) {
				int index = size[0] * size[1] * z +
					size[0] * y + x;					
				regionBuffer[index] = 0;
			}
		}
	}
}

用法:

ImagePointer3D removedRegion = ImageType3D::New();
cfs.createNewItkImage(removedRegion, spacing, direction, origin, size);		

2. 根据已有图像复制一个同样的图像

void CustomFunctions::copyItkImage(const ImagePointer3D& input_image3D, ImagePointer3D& output_image3D)
{
	using DuplicatorType = itk::ImageDuplicator<ImageType3D>;
	DuplicatorType::Pointer duplicator = DuplicatorType::New();
	duplicator->SetInputImage(input_image3D);
	duplicator->Update();
	output_image3D = duplicator->GetOutput();
}

用法:

ImagePointer3D guBoneimageClone;
cfs.copyItkImage(gu_bone_image, guBoneimageClone);

你可能感兴趣的:(医学图像处理,c++)