今天将分享人体三维主动脉血管骨架提取案例。
1、常见3D骨架提取算法
常见的两种图像细化方法有(1)、核滤波器,(2)、决策树。 核滤波器方法是将结构元素应用在图像上,例如迭代地侵蚀物体的表面,直到仅保留骨架为止,该方法通常可以扩展到更高维度上。决策树方法是迭代处理26邻域内中目标和背景体素所有可能的二进制组合,并在每次迭代时找到所有可删除的表面点,虽然该方法仅限于2D和3D,但却比形态滤波器运算速度快。
2、使用ITK函数来实现3D骨架提取算法
ITK的函数中只支持2D骨架提取算法,但有大牛写了基于ITK的3D骨架提取算法,C++源码下载请见原文链接。该函数非常简单,只需要输入二值化的图像即可,输出是3D骨架图像。(如果输入非二值化图像,该函数会默认将非零值设置成1)
该函数既可以在C++中使用,也可以在Python中使用,下面将给出C++和Python使用例子。
C++代码:
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkBinaryThinningImageFilter3D.h"
#include "itkTestingMacros.h"
#include <iostream>
int itkBinaryThinningImageFilter3DTest(int argc, char *argv[])
{
// Verify the number of parameters in the command line
if (argc <= 2)
{
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl;
return EXIT_FAILURE;
}
char *infilename = argv[1];
char *outfilename = argv[2];
const unsigned int Dimension = 3;
typedef unsigned char PixelType;
typedef itk::Image<PixelType, Dimension> ImageType;
// Read image
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(infilename);
TRY_EXPECT_NO_EXCEPTION( reader->Update() );
// Define the thinning filter
typedef itk::BinaryThinningImageFilter3D<ImageType, ImageType> ThinningFilterType;
ThinningFilterType::Pointer thinningFilter = ThinningFilterType::New();
EXERCISE_BASIC_OBJECT_METHODS( thinningFilter, BinaryThinningImageFilter3D,
ImageToImageFilter );
thinningFilter->SetInput(reader->GetOutput());
TRY_EXPECT_NO_EXCEPTION( thinningFilter->Update() );
// output to file
typedef itk::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(thinningFilter->GetOutput());
writer->SetFileName(outfilename);
TRY_EXPECT_NO_EXCEPTION( writer->Update() );
std::cout << "Test finished.";
return EXIT_SUCCESS;
}
Python代码:
import itk
input_filename = sys.argv[1]
output_filename = sys.argv[2]
image = itk.imread(input_filename)
thining_map = itk.BinaryThinningImageFilter3D.New(image)
itk.imwrite(thining_map, output_filename)
3、血管3D骨架提取效果
如图所示是血管二值图像,图中红色点目标就是3D血管骨架结果。
如果碰到任何问题,随时留言,我会尽量去回答的。